Split
Extension method to split string by number of characters.
Source
/// <summary>
/// Extension method to split string by number of characters.
/// </summary>
/// <param name="startindex">The zero-based position to split the specified string.</param>
/// <param name="length">The number of characters to split</param>
public static string[] Split(this string str, int startindex, int length)
{
string[] strrtn = new string[3];
if (startindex == 0)
strrtn = new string[] { str.Substring(startindex, length), str.Remove(startindex, length) };
else if (startindex > 0)
strrtn = new string[] { str.Substring(startindex, length), str.Substring(0, startindex), str.Remove(0, length + startindex) };
return strrtn;
}
Example
string[] A = "Ahmer-Sohail-Shamsi".Split(6, 6);
MessageBox.Show(A[0]);
MessageBox.Show(A[1]);
MessageBox.Show(A[2]);
/*
OUTPUT:
Sohail
Ahmer-
-Shamsi
*/