开发者

C# how to use the \ character in a char datatype

开发者 https://www.devze.com 2022-12-11 18:50 出处:网络
I would like to trim a \\ character from the end of the string. How is this done? MyString.Value.TrimEnd(\'\\\');

I would like to trim a \ character from the end of the string. How is this done?

MyString.Value.TrimEnd('\');

simple doesn't work, and开发者_开发技巧 produces a newline in constant error, please help


Change this to

MyString.Value.TrimEnd('\\');

The slash has to be escaped.


\ is an escape character, use \\ instead.

Bobby


This should work:

MyString.Value.TrimEnd((char)92);
0

精彩评论

暂无评论...
验证码 换一张
取 消