Click here to Skip to main content
15,889,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
string s1="abc$def$hij$klm$"
string[] ary=s1.split("$");
o/p:
abc
def
hij
klm

i want output in the above way using $ symbol
Posted
Comments
Mehdi Gholam 3-Apr-15 6:19am    
So what's the problem?

The split method splits by regular expression, and $ is a special char (it indicates the end of the string), so you have to escape it; add two backslashes before the dollar sign:
Java
String s1 = "abc$def$hij$klm$";
String[] ary = s1.split("\\\\$");
 
Share this answer
 
v5
You need to escape $ in split with a back-slash (\\)).
 
Share this answer
 
v4
Comments
Thomas Daniels 3-Apr-15 6:46am    
I edited your post to make the backslash appear; because CP supports Markdown now, you have to escape the backslash.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900