Full db indexing (untested).
[LanSpider.git] / src / Extensions / Extensions.cs
blobde2391a95ec45cf3effb11b8ec3b6d8918eefbc5
1 namespace Extensions
3 public static class Extensions
5 /// <summary>
6 /// Get the array slice between the index (inclusive and end of array).
7 /// </summary>
8 public static T[] Slice< T >( this T[] source, int start )
10 // Return new array
11 T[] res = new T[source.Length - start];
12 for ( int i = 0; i < source.Length - start; ++i )
14 res[ i ] = source[ i + start ];
16 return res;
19 /// <summary>
20 /// Get the array slice between the two indexes.
21 /// Inclusive for start index, exclusive for end index.
22 /// </summary>
23 public static T[] Slice< T >( this T[] source, int start, int end )
25 // Handles negative ends
26 if ( end < 0 )
28 end = source.Length - start - end - 1;
30 int len = end - start;
32 // Return new array
33 T[] res = new T[len];
34 for ( int i = 0; i < len; ++i )
36 res[ i ] = source[ i + start ];
38 return res;
41 /// <summary>
42 /// Get count of arguments ocurances in this string.
43 /// </summary>
44 /// <param name="string"></param>
45 /// <param name="char"></param>
46 /// <returns></returns>
47 public static int Count( this string @string, char @char )
49 int count = 0;
50 int index = 0;
51 while ( index != -1 )
53 index = @string.IndexOf( @char, index );
54 if ( index != -1 )
56 ++count;
60 return count;