Huy*_* Vũ -1 java string split
I have trouble with the split function in Java. When I try to split a string with a regex "$"
String line = "Vu Quang Huy$2/11/1999$Ha Noi$Nam$CNTT$1.2$12$10000.0";
String[] properties = line.split("$");
Run Code Online (Sandbox Code Playgroud)
It doesn't do any thing. The properties at index 0 is the same as the original string
System.out.println(properties[0]);
Run Code Online (Sandbox Code Playgroud)
And it shows
Vu Quang Huy$2/11/1999$Ha Noi$Nam$CNTT$1.2$12$10000.0
Run Code Online (Sandbox Code Playgroud)
Can anyone help me with this problem? Thanks in advance!
$ in regex means "the end of a string", use \$ instead.
And, you have to escape the '\' as well, so you have to write it like this
String[] properties = line.split("\\$");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
53 次 |
| 最近记录: |