我在 C# 中有一个字符串,想从特定行获取文本,比如 65。如果文件没有那么多行,我想获取“”。如何做到这一点?
最佳答案
快速简单,假设\r\n 或\n 是您的换行序列
string GetLine(string text, int lineNo)
{
string[] lines = text.Replace("\r","").Split('\n');
return lines.Length >= lineNo ? lines[lineNo-1] : null;
}
关于c# - 如何从 C# 中的字符串中获取特定行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2606368/