strspn (String Span) Returns the length of the longest substring that begins at the start of the string and consists only of the characters found in the supplied character array.
Code Snippet
- private int strspn(string InputString, char[] Mask)
- {
- int count = 0;
- foreach (var c in InputString)
- {
- if (!Mask.Contains(c)) break;
- count++;
- }
- return count;
- }
strcspn (String Complement Span) Returns the length of the longest substring that begins at the start of the string and contains none of the characters found in the supplied character array.
Code Snippet
- private int strcspn(string InputString, char[] Mask)
- {
- int count = 0;
- foreach (var c in InputString)
- {
- if (Mask.Contains(c)) break;
- count++;
- }
- return count;
- }
- }
2 comments:
Thanks for this. I was looking for the strspn implementation. For the strcspn implementation, I am using:
InputString.IndexOfAny(Mask);
Won't that work?
Chris
Actually, it would.
Post a Comment