Skip to main content

フォーマット(sprintf)

Python

py
'%s, %s and %s' % ('a', 'b', 'c')

Swift

swift
String.localizedStringWithFormat("%03d-%@", 1, "test")
  • import Foundation が必要
  • 文字列は %s ではなく %@

Ruby

rb
"%s-%05d" % [name, age]

PowerShell

powershell
"{0}-{1}" -f @(name, age)

例によって、こうでもよい。

powershell
"{0}-{1}" -f name, age

{0:XXXX} みたいな形式でフォーマットも指定可

https://docs.microsoft.com/ja-jp/dotnet/api/system.string.format?view=net-5.0

Excel

xlsx
=TEXT(A1, 'yyyy/mm/dd (aaa) hh:mm:ss')

書式の例

txt
#,##0
#,#
0.0%