java - split() function for '$' not working -
this question has answer here:
- how split string in java 29 answers
- what special characters must escaped in regular expressions? 8 answers
i'm doing simple code
string splitstring = "122$23$56$rt"; for(int i=0;i<splitstring.split("$").length;i++){ system.out.println("i got :: "+splitstring.split("$")[i]); }
when split
splitstring.split("$")
it giving me output [122$23$56$rt]
why not splinting on '$'?
string.split()
takes in regex argument , $
metacharacter in java regex api
. therefore, need escape it:
string splitstring = "122$23$56$rt"; for(int i=0;i<splitstring.split("\\$").length;i++){ system.out.println("i got :: "+splitstring.split("\\$")[i]); }
other metacharacters supported java regex api
are: <([{\^-=!|]})?*+.>
Comments
Post a Comment