我在 VBScript 中有一个函数,它在做什么?如何使用 C# 2.0 简化它。
Function FormatString(format, args)
Dim RegExp, result
result = format
Set RegExp = New RegExp
With RegExp
.Pattern = "\{(\d{1,2})\}"
.IgnoreCase = False
.Global = True
End With
Set matches = RegExp.Execute(result)
For Each match In matches
dim index
index = CInt(Mid(match.Value, 2, Len(match.Value) - 2))
result = Replace(result, match.Value, args(index))
Next
Set matches = nothing
Set RegExp = nothing
FormatString = result
End Function
谢谢!
最佳答案
看起来像 .NET 的简化版本 String.Format方法。
它采用带有花括号分隔的占位符(例如 "{0} {1}"
)的格式字符串,并依次用 args< 中的相应值替换每个占位符
数组。您可以将它换成 String.Format
,而不会改变任何功能。
关于c# - 这个 VBScript 函数在做什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7925075/