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

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

问题描述

我有以下格式:
值1是{0},值2是{1}。

我需要将括号中的数字替换为字符串。这很容易在大多数语言中使用string.Format或沿着这些线的东西。



我试过了:

 替换(strFormat,{0},value1)
替换(strFormat,{1},value2)

不起作用。任何解决方案?

解决方案


替换(strFormat,{0} ,value1)


基于你的代码片段,我猜你相信替换变种 strFormat 直接。它不这样工作;您将结果分配给原始变量,如下所示:

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

您也可以指定另一个变量来存储更改后的结果。 :
$ b $ $ p $ str $ c $ str $ str $ str $ str $ str $ str $


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?

解决方案

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)

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

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