且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将一行string []显示为多行?

更新时间:2023-12-04 13:23:46

String.split()看起来可能会有所帮助... ^ ]
String.split() looks like it might help...http://www.rgagnon.com/javadetails/java-0438.html[^]


类型string[]不能为单行字符串".这是字符串数组.您的字符串已经按照以下格式进行了格式化:将字符串分成几行显示.

也许您没有正确提出问题?根据格里夫的回答,如果您需要将一个字符串分成字符串数组,请按行尾将其拆分;否则,请执行以下步骤:如果需要在不同的行中显示字符串数组,则需要将它们与''\ n连接起来.

顺便说一句,行尾序列是平台相关的.请参见 http://en.wikipedia.org/wiki/End_of_line [ http://en.wikipedia.org/wiki/Escape_sequence [
The type string[] cannot be "one-line string". This is array of strings. Your string is already formatted in the form which would show the string separated in several lines.

Maybe you did not formulate the question correctly? If you need to work a string into array of strings, by end of lines, you need to split it, according the answer by Griff; if you need to present array of strings in different lines, you need to concatenated them with ''\n''.

By the way, end-of-line sequence is platform-dependent. See http://en.wikipedia.org/wiki/End_of_line[^].

See also: http://en.wikipedia.org/wiki/Escape_sequence[^].

—SA