jdk1.4中有个很好用的函数,replaceAll(),你可以用它来替换所得到的所有字符,比如replaceAll("\n","<br>")
解决方案 »
- 小弟跪求此错误在那里
- web目录问题
- 求救!!关于页面提交多选问题(checkbox)
- 请大家帮我看一下我的jsp网页放在Webapps目录下为什么不能在网上访问?
- spring 的范例jpetstore中的annotation,attributes,client三个文件夹中的文件是干什么用的?
- 求救:java类的wiki功能源码
- WIN8 64环境eclipse编写的struts2+spring系统war包到winxp32位环境下出错
- 请教:如何限制文件访问?
- jcreator中注释乱码的问题
- 【请教】使用strut2的标签<s:select>怎么设置选项变动后的action?谢谢。
- jsp网页执行数据库操作的问题
- 求助,哪里能找到论坛源代码(Jsp)? 多谢!!!
{
int i=line.indexOf(ch);
StringBuffer sb=new StringBuffer();
if (i==-1)
return line;
sb.append(line.substring(0,i)+rep);
if(i+ch.length()<line.length())
sb.append(replace(line.substring(i+ch.length(),line.length()),ch,rep));
return sb.toString();
}String test='123'
test=replace(test,"'",""");//'->"在注册时可以用于特殊字符的替换
{
if(s == null || s1 == null || s2 == null)
return "";
int i = 0;
boolean flag = false;
if((i = s.indexOf(s1, i)) >= 0)
{
char ac[] = s.toCharArray();
char ac1[] = s2.toCharArray();
int k = s1.length();
StringBuffer stringbuffer = new StringBuffer(ac.length);
stringbuffer.append(ac, 0, i).append(ac1);
i += k;
int j;
for(j = i; (i = s.indexOf(s1, i)) > 0; j = i)
{
stringbuffer.append(ac, j, i - j).append(ac1);
i += k;
} stringbuffer.append(ac, j, ac.length - j);
return stringbuffer.toString();
} else
{
return s;
}
} public static final String htmlToCode(String s)
{
if(s == null)
{
return "";
} else
{
s = replace(s, "<p>", "\n\n");
s = replace(s, "<br>", "\r\n");
s = replace(s, " ", "\t");
s = replace(s, " ", " ");
s = replace(s, "<", "<");
s = replace(s, ">", ">");
s = replace(s, "&", "&");
return s;
}
} public static final String htmlEncode(String s)
{
if(s == null)
return "";
char ac[] = s.toCharArray();
StringBuffer stringbuffer = new StringBuffer(ac.length);
for(int i = 0; i < ac.length; i++)
{
char c = ac[i];
if(c == '<')
stringbuffer.append("<");
else
if(c == '>')
stringbuffer.append(">");
else
if(c == '"')
stringbuffer.append(""");
else
if(c == '&')
stringbuffer.append("&");
else
stringbuffer.append(c);
} return stringbuffer.toString();
}