您如何计算字符串中字符串(实际上是字符)的出现?
问题: I am doing something where I realised I wanted to count how many / s I could find in a string, and then it struck me, that there were several ways to do it, but couldn't decide on what the best (or easiest) was. 我正在做某件事,我意识到我想计算一个字符串中可以找到多少个 / 秒,然后让我感到震惊的是,有几种方法可以做到,但无法决定最好的(或最简单的)是。 At the moment I'm going with something like: 目前,我正在处理类似: string source = "/once/upon/a/time/"; int count = source.Length - source.Replace("/", "").Length; But I don't like it at all, any takers? 但是,我一点都不喜欢它,对吗? I don't really want to dig out RegEx for this, do I? 我真的不想为此挖掘 RegEx ,对吗? I know my string is going