XojoにはC言語の標準関数であるprintfやsprintf等の不定数の引数を持つものはありません。
引数を省略する事の出来るメソッドはあります。
sprintfが使えないと色々と不便なので、似た様なメソッドを作成しました。
ParamArrayを使う事で引数の個数を特定せずに実装出来ます。
Sub FormatString( nFormatStr As String, ParamArray inParam As String )
Var theResultStr As String = ""
Var theTempStr() As String
theTempStr = inFormatStr.Split( "%s" )
If ( theTempStr.Count >= inParam.Count ) Then
//書式の挿入箇所と引数の両方が無くなるまでコピーする
Do
If ( theTempStr.Count > 0 ) And ( inParam.Count > 0 ) Then
theResultStr = theResultStr + theTempStr( 0 ) + inParam( 0 )
theTempStr.RemoveAt( 0 )
inParam.RemoveAt( 0 )
ElseIf ( theTempStr.Count > 0 ) Then
theResultStr = theResultStr + theTempStr( 0 )
theTempStr.RemoveAt( 0 )
ElseIf ( inParam.Count > 0 ) Then
theResultStr = theResultStr + inParam( 0 )
inParam.RemoveAt( 0 )
Else
Exit
End If
loop until ( theTempStr.Count < 0 ) And ( inParam.Count < 0 )
Else
// パラメーターの個数とformatの指示が一致しない
Return( "" )
End If
Return( theResultStr )
End Sub
Stringに限定する事で処理を簡単に出来ます。
整数などを渡したい場合は
FromatString( "This Is Int Value = %s" , theIntValue.ToString("Format") )
とすれば良いだけです。