| 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
|
 |
 |
|
|
subject: the replaceFirst method of String & ????
|
|
|