I have a String in which there are some ASCII control characters (namely RS (0x1e) and US (0x1f)). I defined them in my code as such:
static public final byte RS = 0x1E; static public final byte US = 0x1F;
later in my code, I want to break the string using these characters:
String[] records = content.split(String.valueOf(RS));
but it does not work correctly. After some attempts, I found that it
String[] records = content.split("\u001e");
works, but in this case I have to remember the codes. I use static RS byte also in other parts, so just changing this parameter is not real. I could, of course, create RS_STRING or something else, but that means double work.
Any clean good solution for this?
java string split
Bart friederichs
source share