mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-16 22:13:06 +03:00
32 lines
907 B
C#
32 lines
907 B
C#
|
|
using System;
|
||
|
|
|
||
|
|
namespace Jellyfin.Extensions
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// Provides extensions methods for <see cref="string" />.
|
||
|
|
/// </summary>
|
||
|
|
public static class StringExtensions
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// Counts the number of occurrences of [needle] in the string.
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="value">The haystack to search in.</param>
|
||
|
|
/// <param name="needle">The character to search for.</param>
|
||
|
|
/// <returns>The number of occurrences of the [needle] character.</returns>
|
||
|
|
public static int Count(this ReadOnlySpan<char> value, char needle)
|
||
|
|
{
|
||
|
|
var count = 0;
|
||
|
|
var length = value.Length;
|
||
|
|
for (var i = 0; i < length; i++)
|
||
|
|
{
|
||
|
|
if (value[i] == needle)
|
||
|
|
{
|
||
|
|
count++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return count;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|