Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit d41d7fb

Browse files
committed
Add CountOccurancesOf string extension
1 parent 3b9972f commit d41d7fb

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/ServiceStack.Text/StringExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,19 @@ public static IEnumerable<string> ReadLines(this string text)
919919
}
920920
}
921921

922+
public static int CountOccurancesOf(this string text, char needle)
923+
{
924+
var chars = text.ToCharArray();
925+
var count = 0;
926+
var length = chars.Length;
927+
for (var n = length - 1; n >= 0; n--)
928+
{
929+
if (chars[n] == needle)
930+
count++;
931+
}
932+
return count;
933+
}
934+
922935
#if !XBOX
923936
public static string HexEscape(this string text, params char[] anyCharOf)
924937
{

0 commit comments

Comments
 (0)