java - split() function for '$' not working -


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

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -