I want to replace the question mark (?) in a string with some other words. What is the regular expression for question mark. For example, I want to replace question mark in "word=?" to something else, say "stackoverflow". Then the result would be "word=stackoverflow". What is the syntax in java?
string.replaceFirst("\\?", yourWord)
That will replace the first occurrence of a '?'
in your code with whatever yourWord
is.
If you want to replace every '?'
with yourWord
then use string.replaceAll("\\?", yourWord)
.
See the javadocs for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With