Remove the last three characters from a string

前端 未结 14 1507
南方客
南方客 2021-01-30 15:22

I want to remove last three characters from a string:

string myString = \"abcdxxx\"; 

Note that the string is dynamic data.

相关标签:
14条回答
  • 2021-01-30 16:13
    myString.Remove(myString.Length-3);
    
    0 讨论(0)
  • 2021-01-30 16:13

    The new C# 8.0 range operator can be a great shortcut to achieve this.

    Example:

    var shortenedString = myString[0..^1]
    
    0 讨论(0)
提交回复
热议问题