Trim last character from a string

后端 未结 14 1383
谎友^
谎友^ 2020-11-29 23:59

I have a string say

\"Hello! world!\" 

I want to do a trim or a remove to take out the ! off world but not off Hello.

14条回答
  •  温柔的废话
    2020-11-30 00:42

    if (yourString.Length > 1)
        withoutLast = yourString.Substring(0, yourString.Length - 1);
    

    or

    if (yourString.Length > 1)
        withoutLast = yourString.TrimEnd().Substring(0, yourString.Length - 1);
    

    ...in case you want to remove a non-whitespace character from the end.

提交回复
热议问题