问题描述
我有以下格式:
值1是{0},值2是{1}。
我需要将括号中的数字替换为字符串。这很容易在大多数语言中使用string.Format或沿着这些线的东西。
我试过了:
替换(strFormat,{0},value1)
替换(strFormat,{1},value2)
不起作用。任何解决方案?
替换(strFormat,{0} ,value1)
基于你的代码片段,我猜你相信替换变种 strFormat
直接。它不这样工作;您将结果分配给原始变量,如下所示:
strFormat = Replace(strFormat,{0},value1)
您也可以指定另一个变量来存储更改后的结果。 : I have the following format:Value1 is {0} and Value2 is {1}. I need to replace the numbers in the brackets with strings. This is easily done in most languages using string.Format or something along those lines. How can I do this using only vbscript? I've tried: It does not work. Any solutions? Based on your code snip, I'm guessing you believe Replace mutates You can also assign to another variable to store the changed results, like this: 这篇关于VBScript:格式化字符串最简单的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
$ b $ $ p $ str $ c $ str $ str $ str $ str $ str $ str $ Replace (strFormat, "{0}", value1)
Replace (strFormat, "{1}", value2)
strFormat
directly. It doesn't work like that; You assign the result to the original variable like this:strFormat = Replace (strFormat, "{0}", value1)
strFormat2 = Replace (strFormat, "{0}", value1)