I want to split a string which has content like this:
a$b$c
but when I use:
String data=...
data.split("$");
it does not recognize $ and do not split string but when I replace $ by some Letter like X it works.
does anyone has any Idea?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The split function takes a regular expression, not a string, to match. Your regular expression uses a special character – in this case ‘$’ – so you would need to change it to escape that character:
Also note that split returns an array of strings – Strings are immutable, so they cannot be modified. Any modifications made to the String will be returned in a new String, and the original will not be changed. Hence the
lineData = line.split("\\$");above.