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;
}
String扩展方法
于 2022-10-16 21:33:00 首次发布