当前位置: 技术问答>java相关
诚邀讨论:JSP中怎样判断回车字符,并将其替换为"<br>"??
来源: 互联网 发布时间:2015-06-10
本文导语: 我希望将字符串中的回车字符转换为"",ASP中可以判断字符是否=chr(10),但JSP中如何实现?? | public static final String bbb(String s) {String ss=""; int n = s.length(); int j=1; for (int i = 0 ;i | ...
我希望将字符串中的回车字符转换为"
",ASP中可以判断字符是否=chr(10),但JSP中如何实现??
",ASP中可以判断字符是否=chr(10),但JSP中如何实现??
|
public static final String bbb(String s)
{String ss="";
int n = s.length();
int j=1;
for (int i = 0 ;i
{String ss="";
int n = s.length();
int j=1;
for (int i = 0 ;i
|
jsp 的回车符为
|
//----------------------------一个字符串替换的函数
public static java.lang.String replace(java.lang.String strSource,java.lang.String strFrom,java.lang.String strTo){
java.lang.String strDest = "";
int intFromLen = strFrom.length();
int intPos;
while((intPos=strSource.indexOf(strFrom))!=-1){
strDest = strDest + strSource.substring(0,intPos);
strDest = strDest + strTo;
strSource = strSource.substring(intPos+intFromLen);
}
strDest = strDest + strSource;
return strDest;
}
replace("n","
");//这样就可以了
replace("rn","
");//有些时候回车可能会是rn
public static java.lang.String replace(java.lang.String strSource,java.lang.String strFrom,java.lang.String strTo){
java.lang.String strDest = "";
int intFromLen = strFrom.length();
int intPos;
while((intPos=strSource.indexOf(strFrom))!=-1){
strDest = strDest + strSource.substring(0,intPos);
strDest = strDest + strTo;
strSource = strSource.substring(intPos+intFromLen);
}
strDest = strDest + strSource;
return strDest;
}
replace("n","
");//这样就可以了
replace("rn","
");//有些时候回车可能会是rn
|
//禁用HTML代码编码
public String html(String s){
String re;
re=replace(s,"",">");
re=replace(re,"n","
");
re=replace(re," "," ");
re=replace(re,"'","'");
return re;
}
public String html(String s){
String re;
re=replace(s,"",">");
re=replace(re,"n","
");
re=replace(re," "," ");
re=replace(re,"'","'");
return re;
}
|
String sStr ="" ;
String sBr = "" ;
while (sStr.indexOf("n")!=-1){
sBr + = sStr.substring(0,sStr.indexOf("n")-1)+"
" ;
sStr = sStr.substring(sStr.indexOf("n")+1) ;
}
sBr + =sStr ;
String sBr = "" ;
while (sStr.indexOf("n")!=-1){
sBr + = sStr.substring(0,sStr.indexOf("n")-1)+"
" ;
sStr = sStr.substring(sStr.indexOf("n")+1) ;
}
sBr + =sStr ;
|
换行符为r
硬回车为n
硬回车为n
|
textarea里面,段落之间就是rn
|
public static String TextToHtml(String sourcestr)
{
int strlen;
String restring="", destr = "";
strlen = sourcestr.length();
for (int i=0; i
{
int strlen;
String restring="", destr = "";
strlen = sourcestr.length();
for (int i=0; i
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!