我使用Android Studio 2.2.2
。我有这样的代码:
new StringBuilder ( ).append ( "<script type='text/x-mathjax-config'>" ).append ( "MathJax.Hub.Config({ " ).append ( "showMathMenu: false, " ).append ( "jax: ['input/TeX','output/HTML-CSS'], " ).append ( "extensions: ['tex2jax.js','toMathML.js'], " ).append ( "TeX: { extensions: ['AMSmath.js','AMSsymbols.js'," ).append ( "'noErrors.js','noUndefined.js'] }, " ).append ( "});</script>" ).append ( "<script type='text/javascript' " ).append ( "src='file:///android_asset/MathJax/MathJax.js'" ).append ( "></script>" ).append ( "<span id='math'></span><pre><span id='mmlout'></span></pre>" ).toString ( )
如您所见,它很长并且用一行表示。有没有办法将其转换为:
new StringBuilder ( )
.append ( "<script type='text/x-mathjax-config'>" )
.append ( "MathJax.Hub.Config({ " )
.append ( "showMathMenu: false, " )
.append ( "jax: ['input/TeX','output/HTML-CSS'], " )
.append ( "extensions: ['tex2jax.js','toMathML.js'], " )
.append ( "TeX: { extensions: ['AMSmath.js','AMSsymbols.js'," )
.append ( "'noErrors.js','noUndefined.js'] }, " )
.append ( "});</script>" )
.append ( "<script type='text/javascript' " )
.append ( "src='file:///android_asset/MathJax/MathJax.js'" )
.append ( "></script>" )
.append ( "<span id='math'></span><pre><span id='mmlout'></span></pre>" )
.toString ( )
在上面,每一行都以.append()
开头,并且只包含其中一行。这更具可读性。
注意:
答案 0 :(得分:2)
编辑器 - 代码样式 - Java - 链式方法调用。选择“如果长时砍伐”和“多线时对齐”。或者使用kotlin和它的多行字符串:-)
但你不应该在这里使用StringBuilder
。只需使用+
来连接字符串的各个部分。额外:连接将在编译时而不是运行时发生。