Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串,由于某种原因,有时看起来像这样:string a = "\"C:\\Temp\\1.bat",有时看起来很正常,像这样:string a = "C:\\Temp\\1.bat"
string a = "\"C:\\Temp\\1.bat"
string a = "C:\\Temp\\1.bat"
我如何确定是否需要"\从字符串中修剪前两个,并在必要时修剪它?最后,我希望留下:"C:\\Temp\\1.bat"无论如何。
"\
"C:\\Temp\\1.bat"
你可以这样做:
a = a.TrimStart('\"');
顺便说一句,您不想"\从字符串的开头删除 。这不可能。您要删除的是\".
\"
你的字符串实际上是"C:\Temp\1.bat, the\"是 的转义形式",所以你只需要删除第一个字符!
"C:\Temp\1.bat
"
string a = "\"C:\\Temp\\1.bat" string b = s.SubString(1);