String quote = "Now is the time for all good "+
"men to come to the aid of their country.";
Run Code Online (Sandbox Code Playgroud)
我想在运行时检测断线,当我点击按钮我想知道新线来..因为在TEXTVIEW我想输出相同像这样的字符串没有变化..所以告诉我一些想法或逻辑或源代码....
中没有新行或特殊的"断行"字符
String quote = "Now is the time for all good "+
"men to come to the aid of their country.";
Run Code Online (Sandbox Code Playgroud)
该陈述完全等同于
String quote = "Now is the time for all good men to come to the aid of their country.";
Run Code Online (Sandbox Code Playgroud)
当我点击按钮我想知道新线来..
您可以找到每个新线的位置yourText.indexOf("\n").例如,下面的片段打印29.
String quote = "Now is the time for all good \n" +
"men to come to the aid of their country.";
System.out.println(quote.indexOf('\n'));
Run Code Online (Sandbox Code Playgroud)
我想通过隐形"\n"来拼写一些单词
没有"隐形\n".在源代码中,您必须使用\n或等效的东西.Java不支持heredoc或任何等效的东西.
要将字符串分成多行,您可以执行以下操作:
String quote = "Now is the time for all good " +
"men to come to the aid of their country.";
quote = quote.substring(0, 29) + "\n" + quote.substring(29);
System.out.println(quote);
Run Code Online (Sandbox Code Playgroud)
打印:
Now is the time for all good
men to come to the aid of their country.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8462 次 |
| 最近记录: |