public static X11.TChar[] StringToSByteArray(string text) { if (string.IsNullOrEmpty(text)) { return(new X11.TChar[0]); } X11.TChar[] result = new X11.TChar[text.Length]; for (int charIndex = 0; charIndex < text.Length; charIndex++) { result[charIndex] = (X11.TChar)text[charIndex]; } return(result); }
/// <summary>Determine the index of indicated character within a byte (1 byte (0...255) character) array.</summary> /// <param name="text">The byte (1 byte (0...255) character) array to find the index in.<see cref="X11.TChar[]"/></param> /// <param name="character">The character to find the index for.<see cref="X11.TChar"/></param> /// <returns>The zero-based index on success, or -1 otherwise.<see cref="System.Int32"/></returns> public static int IndexOfSByteArray(X11.TChar[] text, X11.TChar character) { if (text.Length == 0) { return(-1); } for (int charIndex = 0; charIndex < text.Length; charIndex++) { if (text[charIndex] == character) { return(charIndex); } } return(-1); }
/// <summary>Extract a sub-array from a byte (1 byte (0...255) character) array.</summary> /// <param name="text">The byte (1 byte (0...255) character) array to extract a sub-array from.<see cref="X11.TChar[]"/></param> /// <param name="start">The index of the first character to extract.<see cref="System.Int32"/></param> /// <param name="length">The number of characters to extract, or -1 for all characters up to the end.<see cref="System.Int32"/></param> /// <returns>The extracted sub-array on success, or an empty array otherwise.<see cref="X11.TChar[]"/></returns> public static X11.TChar[] SubSByteArray(X11.TChar[] text, int start, int length) { if (start >= text.Length) { return(new X11.TChar[0]); } if (length <= 0) { length = text.Length; } int realLength = (length > 0 && start + length < text.Length ? length : text.Length - start); X11.TChar[] result = new X11.TChar[realLength]; for (int charIndex = 0; charIndex < realLength; charIndex++) { result[charIndex] = text[start + charIndex]; } return(result); }