首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

怎么用String.replaceFirst函数替换“?”

2012-02-15 
如何用String.replaceFirst函数替换“?”Stringstrwheredbbetween?and? str.replaceFirst( \\? ,1234

如何用String.replaceFirst函数替换“?”
String   str   =   "where   db   between   ?   and   ? ";
str.replaceFirst( "\\? ",   "1234 ");
str.replaceFirst( "\\? ",   "5678 ");

希望得到的结果是:str   ==   "where   db   between   1234   and   5678 ";

不知怎么回事,怎么搞也搞不定啊。。。

大虾帮我!谢谢

该函数定义如下:
public   String   replaceFirst(String   regex,
                                                      String   replacement)
使用给定的   replacement   字符串替换此字符串匹配给定的正则表达式的第一个子字符串。

[解决办法]
String str = "where db between ? and ? ";
str = str.replaceFirst( "\\? ", "1234 ");
str = str.replaceFirst( "\\? ", "5678 ");
System.out.println(str);

热点排行