计算某个字符在字符串中出现多少次,然后再出现在其他字符中 [英] Counting how many times a certain char appears in a string before any other char appears

查看:43
本文介绍了计算某个字符在字符串中出现多少次,然后再出现在其他字符中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多琴弦.每个字符串前面至少应包含1个 $ .遍历每个字符串的字符以计​​算每个字符串有多少 $ 个字符的最佳方法是什么.

I have many strings. Each string is prepended with at least 1 $. What is the best way to loop through the chars of each string to count how many $'s there are per string.

例如:

"$hello" - 1
"$$hello" - 2
"$$h$ello" - 2

推荐答案

您可以使用Count方法

You could use the Count method

var count = mystring.Count(x => x == '$')

这篇关于计算某个字符在字符串中出现多少次,然后再出现在其他字符中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆