Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

formatting - VBScript: What is the simplest way to format a string?

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:

Replace (strFormat, "{0}", value1)  
Replace (strFormat, "{1}", value2)

It does not work. Any solutions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Replace (strFormat, "{0}", value1)

Based on your code snip, I'm guessing you believe Replace mutates strFormat directly. It doesn't work like that; You assign the result to the original variable like this:

strFormat = Replace (strFormat, "{0}", value1)

You can also assign to another variable to store the changed results, like this:

strFormat2 = Replace (strFormat, "{0}", value1)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...