需要获取多行字符串以在文本框Java中显示 [英] Need to get a multiline string to display in a textbox Java
本文介绍了需要获取多行字符串以在文本框Java中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在项目中有一个要求. 我在javascript中生成了一个注释字符串.
I have a requirement in my project. I generate a comment string in javascript.
Coping Option: Delete all codes and replace
Source Proj Num: R21AR058864-02
Source PI Last Name: SZALAI
Appl ID: 7924675; File Year: 7924675
我将其发送到服务器,并将其作为字符串存储在db中,然后将其取回并显示在textarea中.
I send this to server where I store it as a string in db and then after that I retrieve it back and show it in a textarea.
我在javascript中将其生成为:
I generate it in javascript as :
codingHistoryComment += 'Source Proj Num: <%=mDefault.getFullProjectNumber()%>'+'\n';
codingHistoryComment += 'Source PI Last Name: <%=mDefault.getPILastName()%>'+'\n';
codingHistoryComment += 'Appl ID: <%=mDefault.getApplId()%>; File Year: <%=mDefault.getApplId()%>'+'\n';
在Java中,我试图将\ n替换为
:
In java I am trying to replace the \n to
:
String str = soChild2.getChild("codingHistoryComment").getValue().trim();
if(str.contains("\\n")){
str = str.replaceAll("(\r\n|\n)", "<br>");
}
但是文本区域仍然填充有"\ n"字符:
However the textarea still get populated with the "\n" characters:
Coping Option: Delete all codes and replace\nSource Proj Num: R21AR058864-02\nSource PI Last Name: SZALAI\nAppl ID: 7924675; File Year: 7924675\n
谢谢.
推荐答案
这是一项有效的测试,请尝试一下:
Here is a test that works, try it out:
String str = "This is a test\r\n test.";
if(str.contains("\r\n")) {
System.out.println(str);
}
这篇关于需要获取多行字符串以在文本框Java中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文