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

前端 未结 13 1347
夕颜
夕颜 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:33

    This is what you object to having to do?

    if (theString.endsWith(theOtherString))
    {
       theString = theString.Substring(0, theString.Length - theOtherString.Length);
    }
    

提交回复
热议问题