提问一下,如何对空格和回车等字符进行转换下面这个有点问题啊...
<%!
String encode(String str)
{
String result;
int l;
if(str=="")
{
result="";
}
else
{
l=str.length();
char[] chr=new char[l];
str.getChars(0,l,chr,0);
result="";
int i;
for(i=0;i<=l-1;i++)
{
switch(chr[i])
{
case '<':
result=result+"<";
break;
case '>':
result=result+">";
break;
case 13:
result=result+"<br>";
break;
case '&':
result=result+"&";
break;
case ' ':
result=result+"\n";
break;
case 9:
result=result+" ";
break;
default:
result=result+String.valueOf(chr[i]);
}
}
}
return result;
}
%>