String concatenation VS string format

后端 未结 4 2320
無奈伤痛
無奈伤痛 2021-02-19 05:23

What is the best approach, simple string concatenation or string.format?

For instance, what is the better to use:

 s:=v1+\' \'+v2 
         


        
4条回答
  •  囚心锁ツ
    2021-02-19 06:11

    I use:

    s := v1 + ' ' + v2;
    

    It's clearest and easiest to understand.

    That is the most important thing.

    You may find a construct that is marginally more efficient, e.g. using TStringBuilder in Delphi 2009. If efficiency is of utmost importance, then do what's necessary in the two or three most critical lines. Everywhere else, use code and constructs that are clear and easy to understand.

提交回复
热议问题