Is it seamlessly possible to do?
scala> val p = "$"
scala> "hello, I have 65 dollars".replaceFirst("dollars", p)
Current result is
java.lang.StringIndexOutOfBoundsException: String index out of range: 1
....
The expected result in scala 2.10:
hello, I have 65 $
Problem is with variable p which stores symbol $, I need to process it as a string not regexp.
Note: I can't modify (e.g. replace all non-letter symbols) the p variable (only standard functions, e.g. .toString)
Note2: The given example is rather toy-example. I'd appreciate a more general solution. I.e. variable p can contain any type of content (symbols, numbers, text,...), therefore replacing "$" for "\\$" doesn.t make much sense
(this is improved version of similar problem: scala string, raw string )