aspose file tools
The moose likes Java in General and the fly likes the replaceFirst method of String  & ???? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "the replaceFirst method of String  & ????" Watch "the replaceFirst method of String  & ????" New topic
Author

the replaceFirst method of String & ????

John Smith
Greenhorn

Joined: Sep 21, 2005
Posts: 13
this is my code
String msg = "sub???".replaceFirst("\\?\\?\\?\\?\\?\\?\\?\\?\\?\\?\\?\\?\\?\\?\\?\\?", "2005012100362541");

why need tow "\\" ?
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
replaceFirst() uses regular expressions. In regular expressions a ? has special meaning and you must use \? to indicate you mean the literal ?. However, in Java \ is an escape character as well and necessitates escaping the escape character resulting in a \\ to indicate a \ in the regular expression.

Also, a simplified version of that regular expression is "\\?{16}" which matches exactly 16 question marks.
John Smith
Greenhorn

Joined: Sep 21, 2005
Posts: 13
thank you very much
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: the replaceFirst method of String & ????
 
Similar Threads
String Replace
indexOf(str)
string question
function replace substring
Replacing a word in a text file