1.使用“+”号
string name = "John";
int age = 30;
string result = "My name is " + name + " and I am " + age + " years old.";
Debug.Log(result);
2.使用string.format
string name = "John";
int age = 30;
string result = string.Format("My name is {0} and I am {1} years old.", name, age);
Debug.Log(result);
3.使用插值字符串
string name = "John";
int age = 30;
string result = $"My name is {name} and I am {age} years old.";
Debug.Log(result);
4.StringBuilder 拼接字符串,(可自行封装相关类去处理)
StringBuilder str = new StringBuilder();
str.Append("My name is Hohn");
以上为常用的四种方式,记得保存,经常用到