[removed] What is the simplest way to format a string?

前端 未结 5 1362
感情败类
感情败类 2020-11-29 10:36

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 usin

5条回答
  •  情话喂你
    2020-11-29 11:25

    Why not? This code works here:

    value1 = "1"
    value2 = "2"
    
    strFormat = "Value1 is {0} and Value2 is {1}."
    strFormat = Replace (strFormat, "{0}", value1)  
    strFormat = Replace (strFormat, "{1}", value2)
    
    MsgBox strFormat
    

    Note I update my strFormat value for every replace.

    If you needs a more flexible implementation, you can go with a regular expression, but doesn't seems required now.

提交回复
热议问题