Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何检测此类型字符串中的新行_Java_Android - Fatal编程技术网

Java 如何检测此类型字符串中的新行

Java 如何检测此类型字符串中的新行,java,android,Java,Android,当我点击按钮时,我想在运行时检测换行符,我想知道新行出现了。。 因为在TEXTVIEW中,我希望输出与此字符串相同,没有任何更改。。请告诉我一些想法、逻辑或源代码……中没有新行或特殊的“换行符” String quote = "Now is the time for all good "+ "men to come to the aid of their country."; 该声明完全等同于 String quote = "Now is the time for

当我点击按钮时,我想在运行时检测换行符,我想知道新行出现了。。
因为在TEXTVIEW中,我希望输出与此字符串相同,没有任何更改。。请告诉我一些想法、逻辑或源代码……

中没有新行或特殊的“换行符”

String quote = "Now is the time for all good "+
               "men to come to the aid of their country.";
该声明完全等同于

String quote = "Now is the time for all good "+
               "men to come to the aid of their country.";

当我点击按钮时,我想知道新的一行出现了。

通过执行
yourText.indexOf(“\n”)
,您可以找到每一行的位置。例如,下面的代码片段打印了29条

String quote = "Now is the time for all good men to come to the aid of their country.";


ya我想通过Invisible“\n”说出一些单词

没有“不可见的
\n
”。在源代码中,您必须使用
\n
或类似的东西。Java不支持或任何与之相当的东西

要将字符串拆分为多行,可以执行以下操作:

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'));
其中打印:

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

“\n”字符指定换行符

Now is the time for all good 
men to come to the aid of their country.

如果您的GUI在这一点之前突破了界限,您需要以某种方式禁用换行。

您能用一个不可见的字符(如“\n”@user642,如@aioobe)分隔每个部分吗?在他的回答中,您的问题的字符串中没有换行符。这是打字错误吗?您的字符串中有
\n
吗?是的,我想用“不可见”\n来表达一些单词。如果您想继续收到下面这样的好答案,您需要接受对您有帮助的答案。单击答案左侧的复选标记。
"Now is the time for all good\nmen to come to the aid of their country."