How to change 1 char in the string?

后端 未结 7 1793
天涯浪人
天涯浪人 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 18:16

    I made a Method to do this

        string test = "Paul";
        test = ReplaceAtIndex(0, 'M', test);
    
        (...)
    
        static string ReplaceAtIndex(int i, char value, string word)
        {
            char[] letters = word.ToCharArray();
            letters[i] = value;
            return string.Join("", letters);
        }
    
    0 讨论(0)
提交回复
热议问题