regex - how to find all the double characters in a string in c# -


i trying count of double characters in string using c#,i.e "ssss" should 2 doubles not 3 doubles.

for example right have loop in string this

string s="shopkeeper"; for(int i=1;i<s.length;i++) if(s[i]==s[i-1]) d++; 

the value of d @ end should 1

is there shorter way this? in linq or regex? , perfomance implications, effective way? help

i have read [how check repeated letters in string c#] , it's helpful, doesn't address double characters, looking double characters

try following regex extract double characters: "(.)\1"

upd: simple example:

foreach (var match in regex.matches("shhopkeeper", @"(.)\1"))    console.writeline(match); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -