try:<%
String sTs = "。ABCDE%" ;
int index ;
String re = "A" ;
String pre = "a" ;
if ((index=sTs.indexOf(re))!=-1)
out.print(sTs.substring(0,index)+pre+sTs.substring(index+re.length())) ; re = "E%" ;
pre = "hh" ;
if ((index=sTs.indexOf(re))!=-1)
out.print(sTs.substring(0,index)+pre+sTs.substring(index+re.length())) ;%>
String sTs = "。ABCDE%" ;
int index ;
String re = "A" ;
String pre = "a" ;
if ((index=sTs.indexOf(re))!=-1)
out.print(sTs.substring(0,index)+pre+sTs.substring(index+re.length())) ; re = "E%" ;
pre = "hh" ;
if ((index=sTs.indexOf(re))!=-1)
out.print(sTs.substring(0,index)+pre+sTs.substring(index+re.length())) ;%>
解决方案 »
- 赶集和58同城分别用什么语言架设的?
- 打开jsp页面报错 MyEclipse里
- 高分解答 java 实现下载功能问题
- 在线等!100分!在java文件里,怎样获得web应用的根目录
- 请问jsp学到可以独立开发论坛的水平是种什么样的水平?工资会有多高啊?
- 很简单的一个问题,在线等候回音、、、、、
- 小问题,为什么运行这句:if(shenpibumen.equals("财务部"))提示:NullPointerException
- 如何实现jsp调用com组件?
- tomcat4.1下用jndi连接sql server2000出现问题!!!在线等待
- 用Java Servlet作一个表单的提交程序
- 怎样搭建jdbc访问oracle的软件环境?
- jsp ?? 和asp php 不是一会事吧。。。? 特点是??
public string eliminateStr(String srcString,String token){
try{
StringTokenizer st=new StringTokenizer(srcString,token);
String rstString="";
while(st.hasMoreTokens())
rstString+=st.nextToken();
}catch(Exception e){}
return (str.equals(""))?srcString:rstString
}
* Replaces one string with another throughout a source string.
*
* @param in the source String
* @param from the sub String to replace
* @param to the sub String to replace with
* @return a new String with all occurences of from replaced by to
*/
public static String replaceInString(String in, String from, String to) {
if (in == null || from == null || to == null) {
return in;
} StringBuffer newValue = new StringBuffer();
char[] inChars = in.toCharArray();
int inLen = inChars.length;
char[] fromChars = from.toCharArray();
int fromLen = fromChars.length; for (int i = 0; i < inLen; i++) {
if (inChars[i] == fromChars[0] && (i + fromLen) <= inLen) {
boolean isEqual = true;
for (int j = 1; j < fromLen; j++) {
if (inChars[i + j] != fromChars[j]) {
isEqual = false;
break;
}
}
if (isEqual) {
newValue.append(to);
i += fromLen - 1;
}
else {
newValue.append(inChars[i]);
}
}
else {
newValue.append(inChars[i]);
}
}
return newValue.toString();
}
public static String replace(String str,String oldstr,String newstr){
String ret = str;
int strlen1 = oldstr.length();
while(ret.indexOf(oldstr)!=-1){
int strlen = ret.length();
int index = ret.indexOf(oldstr);
ret = ret.substring(0,index) + newstr + ret.substring(index+strlen1,strlen);
}
return ret;
}
/**
* Replaces one string with another throughout a source string.
*
* @param in the source String
* @param from the sub String to replace
* @param to the sub String to replace with
* @return a new String with all occurences of from replaced by to
*/
public static String replaceInString(String in, String from, String to) {
if (in == null || from == null || to == null) {
return in;
} StringBuffer newValue = new StringBuffer();
char[] inChars = in.toCharArray();
int inLen = inChars.length;
char[] fromChars = from.toCharArray();
int fromLen = fromChars.length; for (int i = 0; i < inLen; i++) {
if (inChars[i] == fromChars[0] && (i + fromLen) <= inLen) {
boolean isEqual = true;
for (int j = 1; j < fromLen; j++) {
if (inChars[i + j] != fromChars[j]) {
isEqual = false;
break;
}
}
if (isEqual) {
newValue.append(to);
i += fromLen - 1;
}
else {
newValue.append(inChars[i]);
}
}
else {
newValue.append(inChars[i]);
}
}
return newValue.toString();
}
-建议做字符比对时用ASCII
相应前台的onKeypress事件时进行判断