c# string character replace

前端 未结 4 1816
一向
一向 2021-01-14 18:04

I have a string where the third last character is sometimes a , If this is the case I want to replace it with a . The string could also have other

4条回答
  •  青春惊慌失措
    2021-01-14 18:39

    string text = "Hello, World,__";
    
    if (text.Length >= 3 && text[text.Length - 3] == ',')
    {
        text = text.Substring(0, text.Length - 3) + "." + text.Substring(text.Length - 2);
    }
    
    // text == "Hello, World.__"
    

提交回复
热议问题