这是在网上找的方法,怕忘记所以记下来,
textarea 录入时带有格式,录入数据库不必处理,如果显示时仍放在
textarea ,没有问题,但是如果直接打在页面上格式就没了,在打在页面上之前调用下面的方法
public static String zhuanyi(String sp,String sp1,String sp2)
{
String sTemp = sp;
String str ="";
if(sp==null||sp.equals(""))
{
return str;
}
try
{
int iIndex=sTemp.indexOf(sp1);
int iStar = 0;
while(iIndex!=-1)
{
String s1= sTemp.substring(iStar,iIndex);
if(iIndex<sTemp.length())
{
sTemp = sTemp.substring(iIndex+1,sTemp.length());
s1 = s1+sp2;
str = str+s1;
iIndex = sTemp.indexOf(sp1);
}
}
str = str+sTemp;
}
catch(Exception e)
{
}
return str;
}
用了一下蛮好使,所以记下来,经备后用.SP要转的字符串,SP1"/n",SP2"<br>"
public static String zhuanyi(String sp,String sp1,String sp2)
{
String sTemp = sp;
String str ="";
if(sp==null||sp.equals(""))
{
return str;
}
try
{
int iIndex=sTemp.indexOf(sp1);
int iStar = 0;
while(iIndex!=-1)
{
String s1= sTemp.substring(iStar,iIndex);
if(iIndex<sTemp.length())
{
sTemp = sTemp.substring(iIndex+1,sTemp.length());
s1 = s1+sp2;
str = str+s1;
iIndex = sTemp.indexOf(sp1);
}
}
str = str+sTemp;
}
catch(Exception e)
{
}
return str;
}
用了一下蛮好使,所以记下来,经备后用.SP要转的字符串,SP1"/n",SP2"<br>"