private static ValuePos _lastValuePos(StringBuilder sb, params char[] separators) { var res = new ValuePos(); if (sb.Length < 1) return res; res.EndIndex = sb.Length - 1; // omit ending spaces: "aaa bbb ccc " while (separators.Contains(sb[res.EndIndex]) && (res.EndIndex >= 0)) { res.EndIndex--; } // Empty string without words " " if ((res.EndIndex == 0) && separators.Contains(sb[0])) { res.EndIndex = -1; return res; } // "Another words and an A" res.StartIndex = res.EndIndex; // "A " if (res.StartIndex == 0) return res; // search for starting spaces: " aaa" while (separators.Contains(sb[res.StartIndex]) && (res.StartIndex >= 0)) { res.StartIndex--; } return res; }
private static ValuePos _firstValuePos(StringBuilder sb, params char[] separators) { var res = new ValuePos(); if (sb.Length < 1) return res; res.StartIndex = 0; // omit beginning spaces: " aaa bbb ccc" while (separators.Contains(sb[res.StartIndex]) && (res.StartIndex < sb.Length)) { res.StartIndex++; } // Empty string without words " " if ((res.StartIndex == sb.Length) && separators.Contains(sb[res.StartIndex])) { res.StartIndex = -1; return res; } // It could be one-char-word: " A and another words " res.EndIndex = res.StartIndex; // " A" if (res.EndIndex == sb.Length - 1) return res; // search for ending spaces: "aaa " while (!separators.Contains(sb[res.EndIndex]) && (res.EndIndex < sb.Length)) { res.EndIndex++; } return res; }