英文:
Split the line and add it in front of next chunk
问题
我将每个块转换为字符串。如何找到最后一行,如果不以闭括号“}”结尾,则从此块中分割出来。然后保留该行,以便在下一个块的前面添加它。
代码:
if (rslt.Byte != null)
{
// 如何检查内容是否以“}”结尾,
// 如果不是,则保留该行以在下一个块的前面添加它。
content = System.Text.Encoding.Default.GetString(rslt.Byte);
}
英文:
I convert each chunk as string. How I find the last line fed, spilt it from this chunk if does not end with closing bracket "}". And keep that line to add it in front of the next chunk.
Code:
if (rslt.Byte != null)
{
// How to check if content ends with "}",
// If no, keep that line to add it in front of next chunk.
content = System.Text.Encoding.Default.GetString(rslt.Byte);
}
答案1
得分: 0
感谢您,我会将其作为答案发布。希望能够帮助更多人。
if (!content.TrimEnd().EndsWith("}")) {
int lastBracketIndex = content.LastIndexOf("}");
string lastLine = content.Substring(lastBracketIndex + 1);
content = content.Substring(0, lastBracketIndex + 1);
}
英文:
Thank you and I post it as answer. Hoping it can help more people.
if (!content.TrimEnd().EndsWith("}")) {
int lastBracketIndex = content.LastIndexOf("}");
string lastLine = content.Substring(lastBracketIndex + 1);
content = content.Substring(0, lastBracketIndex + 1); }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论