How to change 1 char in the string?

后端 未结 7 1794
天涯浪人
天涯浪人 2021-01-03 17:43

I have this code:

string str = \"valta is the best place in the World\";

I need to replace the first symbol. When I try this:



        
7条回答
  •  被撕碎了的回忆
    2021-01-03 17:54

    Strings are immutable. You can use the string builder class to help!:

    string str = "valta is the best place in the World";
    
    StringBuilder strB = new StringBuilder(str);
    
    strB[0] = 'M';
    

提交回复
热议问题