【发布时间】:2017-12-13 19:53:39
【问题描述】:
如何计算字符串中反斜杠的数量?
我尝试了以下方法,但都没有奏效。
string s = @"\a\a\n\u\u0013((((\a\b\n"; // output must be 8
int count = s.Count(a => a == "\\"); // Operator == cant be applied of type char & string
int count = s.Count(a => a == "\"); // newline in constant
int count = s.Split('\\').Length // it doesnt count
【问题讨论】:
-
对于您的每个问题,简单的谷歌搜索都会产生大量帖子,就像我选择用来结束您的问题的帖子一样。下次问问题之前请多加小心。