2

I have these set of strings that I get from a PostgreSQL DB:

"WITH DELIMITER E'\037'"
"WITH DELIMIER E'\01f'"
"WITH DELIMITER '|'"

I need to extract whatever is between the single quotes and use it to split and join a string. Something along the lines:

String delimiter = delimiter.substring(delimiter.indexOf("'")+1, delimiter.indexOf("'",delimiter.indexOf("'")+1));
String[] splitString = originalString.split(delimiter);
//Do something with it...
String joinedString = StringUtils.join(splitString, delimiter);

The problem is that Java takes \037 (read from DB into a String) and reads it as \\037 (would print as "\037") and I need \037 (the special character) for the split and join functions.

I need a way to take the values between single quotes (\037, \01f, |, and so on) and convert them to special characters.

That would be:

String originalString = "\\037"
String convertedString = "\037"

Also, the pipe (|) is a metacharacter in Java and in order for me to split it I had to do the following:

String[] splitString = originalString.split(Pattern.quote("|"));

I don't want to do an if condition, I would like something better. Thanks in advance for your help

1
  • Wow, you are right! I used the second solution as it was easier to understand. Thanks for the help!
    – kiket2ride
    Jun 22, 2017 at 11:36

1 Answer 1

0

I think you should use this. It's more easy and you don't care about the special character.

2
  • Thanks for the answer Wouldn't I be having the same issue? If I call it with function withDelimiter(char delimiter) I would still be having to send the special character, right?
    – kiket2ride
    Jun 22, 2017 at 11:14
  • Hi Rom! Your answer looks useful, but it would be better if you provided a summary text in it, not just the link. That makes it quicker for readers to evaluate, and it continues being useful if the linked side disappears or moves. See Provide context for links in the How do I write a good answer? help page.
    – Lii
    Jun 22, 2017 at 11:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.