I read from a properties file a parameter like this {TA;TD;TE;TG;TI;TN;TNG;TP;TR;TS;TT}, and I need to split it to remove {} and ;. For that I use:
String[] zzz = myString.split("[{;}]");
The problems comes when sending that string to a method that must add it to database (it doesn’t matter how), and then realize that there’s a first element that is empty. That means, when I print it, I see:
blank space
TA
TD
TE
…etc
If I debug it, I see that the elements being extracted from the initial string are: “”, “TA”, “TD”, “TE”, etc.
And because of this “” (the method where the string is sent automatically inserts comma between elements) my row in database is like that:
,TA,TD,TE… etc
How can I avoid that? I’ve tried also to split it with the limiter parameter, but it doesn’t work either.
Thanks in advance.
You can use make this simple change to your code:
This just skips over the first char, which is an open brace. The regex can be slightly simpler, too, since you don’t have to split on the open brace anymore.