//------------------------------------------------------------ // Game Framework // Copyright © 2013-2021 loyalsoft. All rights reserved. // Homepage: http://www.game7000.com/ // Feedback: http://www.game7000.com/ //------------------------------------------------------------ /// /// 对 string 的扩展方法。 /// public static class StringExtension { /// /// 从指定字符串中的指定位置处开始读取一行。 /// /// 指定的字符串。 /// 从指定位置处开始读取一行,读取后将返回下一行开始的位置。 /// 读取的一行字符串。 public static string ReadLine(this string rawString, ref int position) { if (position < 0) { return null; } int length = rawString.Length; int offset = position; while (offset < length) { char ch = rawString[offset]; switch (ch) { case '\r': case '\n': if (offset > position) { string line = rawString.Substring(position, offset - position); position = offset + 1; if ((ch == '\r') && (position < length) && (rawString[position] == '\n')) { position++; } return line; } offset++; position++; break; default: offset++; break; } } if (offset > position) { string line = rawString.Substring(position, offset - position); position = offset; return line; } return null; } }