Why can’t I split a string with the dollar sign?

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:

String line = ...
String[] lineData = line.split("\\$");

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)