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

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -