当前位置: 技术问答>java相关
请问jsp的替换函数是什么?就如同ASP的replace()
来源: 互联网 发布时间:2015-05-18
本文导语: 请问jsp的替换函数是什么?就如同ASP的replace() 能否给举个正确的例子谢谢。 | publicstaticStringreplace(StringstrSource,StringstrFrom,StringstrTo) { if(str...
请问jsp的替换函数是什么?就如同ASP的replace()
能否给举个正确的例子谢谢。
能否给举个正确的例子谢谢。
|
public static String replace(String strSource, String strFrom, String strTo)
{
if(strFrom == null || strFrom.equals(""))
return strSource;
String strDest = "";
int intFromLen = strFrom.length();
int intPos;
while((intPos = strSource.indexOf(strFrom)) != -1)
{
strDest = strDest + strSource.substring(0,intPos);
strDest = strDest + strTo;
strSource = strSource.substring(intPos + intFromLen);
}
strDest = strDest + strSource;
return strDest;
}
{
if(strFrom == null || strFrom.equals(""))
return strSource;
String strDest = "";
int intFromLen = strFrom.length();
int intPos;
while((intPos = strSource.indexOf(strFrom)) != -1)
{
strDest = strDest + strSource.substring(0,intPos);
strDest = strDest + strTo;
strSource = strSource.substring(intPos + intFromLen);
}
strDest = strDest + strSource;
return strDest;
}
|
自己写
|
//----------------------------一个字符串替换的函数
public static java.lang.String replace(java.lang.String strSource,java.lang.String strFrom,java.lang.String strTo){
java.lang.String strDest = "";
int intFromLen = strFrom.length();
int intPos;
while((intPos=strSource.indexOf(strFrom))!=-1){
strDest = strDest + strSource.substring(0,intPos);
strDest = strDest + strTo;
strSource = strSource.substring(intPos+intFromLen);
}
strDest = strDest + strSource;
return strDest;
}
//-----------------------------------end of replace
public static java.lang.String replace(java.lang.String strSource,java.lang.String strFrom,java.lang.String strTo){
java.lang.String strDest = "";
int intFromLen = strFrom.length();
int intPos;
while((intPos=strSource.indexOf(strFrom))!=-1){
strDest = strDest + strSource.substring(0,intPos);
strDest = strDest + strTo;
strSource = strSource.substring(intPos+intFromLen);
}
strDest = strDest + strSource;
return strDest;
}
//-----------------------------------end of replace
|
//----------------------------一个字符串替换的函数
public static java.lang.String replace(java.lang.String strSource,java.lang.String strFrom,java.lang.String strTo){
java.lang.String strDest = "";
int intFromLen = strFrom.length();
int intPos;
while((intPos=strSource.indexOf(strFrom))!=-1){
strDest = strDest + strSource.substring(0,intPos);
strDest = strDest + strTo;
strSource = strSource.substring(intPos+intFromLen);
}
strDest = strDest + strSource;
return strDest;
}
//-----------------------------------end of replace
public static java.lang.String replace(java.lang.String strSource,java.lang.String strFrom,java.lang.String strTo){
java.lang.String strDest = "";
int intFromLen = strFrom.length();
int intPos;
while((intPos=strSource.indexOf(strFrom))!=-1){
strDest = strDest + strSource.substring(0,intPos);
strDest = strDest + strTo;
strSource = strSource.substring(intPos+intFromLen);
}
strDest = strDest + strSource;
return strDest;
}
//-----------------------------------end of replace
|
String 的method:
String replace(char oldChar, char newChar)
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
String replace(char oldChar, char newChar)
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.