Trim string from the end of a string in .NET - why is this missing?

前端 未结 13 1343
夕颜
夕颜 2020-12-13 12:08

I need this all the time and am constantly frustrated that the Trim(), TrimStart() and TrimEnd() functions don\'t take strings as inputs. You call EndsWith() on a string, an

13条回答
  •  执念已碎
    2020-12-13 12:41

    Regex replace may be your friend in this instance.

    var str = "Hello World!";
    str = Regex.Replace(str, @"World!$", "");
    //str == "Hello"
    

提交回复
热议问题