Pregunta

I am inserting a string into a database and need to eliminate the beginning and ending quotes in the string.

I am using:

String a = rows[0].replaceAll("^\"", "").replaceAll("\"$", "");`

This gives me: "134432534"23" => 134432534"23 but is there a better way to do this?

¿Fue útil?

Solución

I really do not see how your call to replace is typically bad here, but you could simplify this.

String a = rows[0].replaceAll("^\"|\"$", "");

To remove the first character and last character from the string, considering they are always quotes, use..

String a = rows[0].substring(1, rows[0].length()-1);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top