java - Having trouble with "replaceall" command -


i have string

s1 = "7+8"; 

and

s2 = "7+"; 

i using following code subtract s2 s1

system.out.println(s1.replaceall(s2,"")); 

but giving output as

"+8" 

why happening??

the regular expression "7+" matches 1 or more instances of "7". replaced, leaving "+8".

if want match exact strings, rather regular expressions, use replace instead of replaceall.

s1.replace(s2, "") 

Comments

Popular posts from this blog

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -

c# - MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(3243,9): error MSB4094 -