VBScript:格式化字符串的最简单方法是什么? [英] VBScript: What is the simplest way to format a string?

查看:46
本文介绍了VBScript:格式化字符串的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式:值 1 为 {0},值 2 为 {1}.

I have the following format: Value1 is {0} and Value2 is {1}.

我需要用字符串替换括号中的数字.这在大多数语言中使用 string.Format 或类似的东西很容易完成.如何仅使用 vbscript 执行此操作?

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?

我试过了:

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

它不起作用.有什么解决办法吗?

It does not work. Any solutions?

推荐答案

替换(strFormat, "{0}", value1)

根据您的代码片段,我猜您相信 Replace 会直接改变 strFormat.它不是那样工作的;您可以像这样将结果分配给原始变量:

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)

这篇关于VBScript:格式化字符串的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆