String str1="your're";
String str2=str1.subString(0,5)+"''"+str1.subString(5,7);
String str2=str1.subString(0,5)+"''"+str1.subString(5,7);
解决方案 »
- 做表情
- Database 导不进来?
- 用JAVA如何实现对软件的自动升级
- 怎样将int型,转换为string型?
- 编辑table某一个表格,然后点击其他按钮,如何保存table中的数据?
- 我有两个简单的java类文件hello.java,helloHome.java在同一个hello目录下,为什么helloHome.java老是说Hello(是Hello.java中的类阿)不
- 帮帮忙给点见意想法什么的(很急)
- 请问BMP和CMP分别个应用于那些情况
- 哪位师兄师姐有《java2类库》orjava的API中文联机文档阿?
- JBUILDER下编写的APPLET怎么在IE下运行?请求支援。
- 请问怎样在java中定义String数组?:(((这么简单的事都不会!急急急:((
- 怎么做成....
s.replace('\'','\"');
/**
* String sOld要被替换的字符串(')
* String sNew替换成的字符串('')
* String sLine整个字符串(your'reyour'reyour'reyour're)
*/
String ReplaceAllStr(String sOld,String sNew,String sLine)
{
int iPosition;
iPosition=sLine.indexOf(sOld,0);
String sLeft,sRight;
while(iPosition!=-1)
{
sLeft=sLine.substring(0,iPosition);
sRight=sLine.substring(iPosition+sOld.length());
sLine=sLeft+sNew+sRight;
iPosition=iPosition+sNew.length();
iPosition=sLine.indexOf(sOld,iPosition);
}
return sLine;
}
replace all ' into " directly
\' ==', \" ==", either of them is one char not two characters
/**
* Returns a new string resulting from replacing all occurrences of
* <code>oldChar</code> in this string with <code>newChar</code>.
* <p>
* If the character <code>oldChar</code> does not occur in the
* character sequence represented by this <code>String</code> object,
* then a reference to this <code>String</code> object is returned.
* Otherwise, a new <code>String</code> object is created that
* represents a character sequence identical to the character sequence
* represented by this <code>String</code> object, except that every
* occurrence of <code>oldChar</code> is replaced by an occurrence
* of <code>newChar</code>.
* <p>
* Examples:
* <blockquote><pre>
* "mesquite in your cellar".replace('e', 'o')
* returns "mosquito in your collar"
* "the war of baronets".replace('r', 'y')
* returns "the way of bayonets"
* "sparring with a purple porpoise".replace('p', 't')
* returns "starring with a turtle tortoise"
* "JonL".replace('q', 'x') returns "JonL" (no change)
* </pre></blockquote>
*
* @param oldChar the old character.
* @param newChar the new character.
* @return a string derived from this string by replacing every
* occurrence of <code>oldChar</code> with <code>newChar</code>.
*/
public String replace(char oldChar, char newChar) {
if (oldChar != newChar) {
int len = count;
int i = -1;
char[] val = value; /* avoid getfield opcode */
int off = offset; /* avoid getfield opcode */ while (++i < len) {
if (val[off + i] == oldChar) {
break;
}
}
if (i < len) {
char buf[] = new char[len];
for (int j = 0 ; j < i ; j++) {
buf[j] = val[off+j];
}
while (i < len) {
char c = val[off + i];
buf[i] = (c == oldChar) ? newChar : c;
i++;
}
return new String(0, len, buf);
}
}
return this;
}