/// <summary> /// 从行文本头或尾开始截取文本直到空白符 /// </summary> /// <param name="row"></param> /// <param name="position"></param> /// <param name="checkIngnore">是否先从行文本中截取—</param> /// <returns></returns> private static string GetUntilSpaceFromRow(ref string row, PositionInRow position, bool checkIngnore = true) { if (checkIngnore && GetIgnoreSymbolFromRow(ref row, position)) { return(IGNORE_SYMBOL); } Regex regex; switch (position) { case PositionInRow.Start: regex = new Regex(@"^\S+\s*"); break; case PositionInRow.End: regex = new Regex(@"\s*\S+$"); break; default: throw new NotImplementedException("GetUntilSpaceFromRow不支持此position"); } var match = regex.Match(row); string r = ""; if (match.Success) { r = match.Value.Trim(); row = regex.Replace(row, "").Trim(); } return(r); }
/// <summary> /// 从行文本中截取— /// </summary> /// <returns></returns> private static bool GetIgnoreSymbolFromRow(ref string row, PositionInRow position) { Regex regex; switch (position) { case PositionInRow.Start: regex = new Regex(@"^" + IGNORE_SYMBOL + @"\s*"); break; case PositionInRow.End: regex = new Regex(@"\s*" + IGNORE_SYMBOL + @"$"); break; default: regex = new Regex(@"\s" + IGNORE_SYMBOL + @"\s+"); break; } var match = regex.Match(row); bool r = false; if (match.Success) { r = true; row = regex.Replace(row, "").Trim(); } return(r); }