怎么算子串出现的? [英] How to count of sub-string occurrences?
本文介绍了怎么算子串出现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这样的字符串:
MyString的=OU = Level3的,OU =级别2,OU = 1级,DC =域,DC = com的;
那么我想知道的子串的出现多少时间OU =此字符串。随着单个字符,也许是这样的:
诠释计数= MyString.Split(OU =)长度 - 1 ;
但拆分
仅适用于字符
,而不是字符串
。
另外如何找到位置ñ出现?例如,第二的位置OU =
中的字符串?
如何解决这个问题?
解决方案
Regex.Matches(输入,OU =)。伯爵
Suppose I have a string like:
MyString = "OU=Level3,OU=Level2,OU=Level1,DC=domain,DC=com";
then I want to know how many time of occurrences of sub-string "OU=" in this string. With single char, maybe there is something like:
int count = MyString.Split("OU=").Length - 1;
but Split
only works for char
, not string
.
Also how to find the position of n occurrences? For example, the position of 2nd "OU="
in the string?
How to resolve this issue?
解决方案
Regex.Matches(input, "OU=").Count
这篇关于怎么算子串出现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文