String strToReplace="abc[todo1]dfdjf[todo4]rer";
String strReplaced = "OK";
String strResult="";
String s1="[";
String s2="]";
int index1=strToReplace("s1");
int index2=0;
while(index1!=-1)
{
index2=strToReplace("s2",index1);
if(index2==-1)
break;
strToReplace=strToReplace.substring(0,index1)+strReplace+strToReplace.substring(index2+s2.length());
}
String strReplaced = "OK";
String strResult="";
String s1="[";
String s2="]";
int index1=strToReplace("s1");
int index2=0;
while(index1!=-1)
{
index2=strToReplace("s2",index1);
if(index2==-1)
break;
strToReplace=strToReplace.substring(0,index1)+strReplace+strToReplace.substring(index2+s2.length());
}
解决方案 »
- 求用Struts 2+Spring+Hibernate开发的<企业人事管理系统>
- struts连接数据库出错
- myeclipse中新建html 文件后打不开
- tomcat部署手机程序服务器端后如何以手机模式查看页面?
- 100分相赠,如解决SSH的Servlet action is not available错误!!拜请高手进!!!!!
- 一个解析xml数据的问题,求方案
- 我有本EJB的书,但是上面的例子用什么开发啊?始终很迷惑
- 在weblogic如何测试配置的数据库连接池是否设置成功?
- 有谁知道哪里有关于xml的电子书下载?
- 链接先跳转到servlet再转发到一个jsp页面,和直接到jsp不同吗
- 什么是类集,类集的作用又是什么!
- 设计一个pro,用程序员设计底层的数据库结构吗?还是说由专人负责...
String strReplaced = "OK";
String strResult="";for(int iPos=0;strToReplace[iPos]!='\0';iPos++)
{
if(strToReplace[iPos]=='[')
{
for(;strToReplace[iPos]!=']'&&strToReplace[iPos]!='\0';iPos++);
strResult+="OK";
}
else
{
strResult+=strToReplase[iPos];
}
}
class ttt1
{
public static void main(String[] args)
{
String strToReplace="abc[todo1]dfdjf[todo4]rer";
String strReplaced = "OK";
String strResult="";
String s1="[";
String s2="]";
int index1=strToReplace.indexOf(s1);
int index2=0;
while(index1!=-1)
{
index2=strToReplace.indexOf(s2,index1);
if(index2==-1)
break;
strToReplace=strToReplace.substring(0,index1)+strReplaced+strToReplace.substring(index2+s2.length());
index1=strToReplace.indexOf(s1,index2);
}
System.out.println(strToReplace);
}
}
{
StringBuffer result=new StringBuffer("");
char cc;
int len=strToReplace.length();
for(int i=0;i<len;i++)
{
cc=strToReplace.charAt(i);
if(cc=='['||cc==']')
{
result.append(reg);
}
else
{
result.append(cc);
}
}
return result.toString();
}
谢谢各位!顺便问一下:
能否通过String 的 replaceAll(String regex, String replacement)来处理?
关键是regex怎么写(要求不要区分大小写)?
只是提供了replace(char oldChar, char newChar)
而replaceAll(String regex,String replacement)只是在1.4版本中才得以支持?