gpt4 book ai didi

java - 如何用 StringBuffer 逐字追加\n?

转载 作者:行者123 更新时间:2023-12-03 02:45:44 27 4
gpt4 key购买 nike

如何按字面意思附加“\n”,而不是像特殊字符那样。

我不会实现这个目标:

StringBuffer st = new StringBuffer;

st.append(text1);
st.append("\n");
st.append(text2);

输出字符串为:

text1 \n text2

不是

text1
text2

最佳答案

StringBuffer st = new StringBuffer();
st.append("Hello");
st.append("\\n"); //<- the first \ escapes the second
st.append("World");

关于java - 如何用 StringBuffer 逐字追加\n?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4245461/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com