分割线并将其添加到下一个块的前面

huangapple go评论62阅读模式
英文:

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); }

huangapple
  • 本文由 发表于 2023年2月6日 03:17:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75354868.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定