In Java, I want to get rid of the leading and trailing brackets in a String.
Given input:
"[ hello, char[]={a,b,c} ... bye ]"
How can I produce the output of
" hello, char[]={a,b,c} ... bye "
only the leading [ and trailing ] is removed... How can I do that in Java?
String i = "[ hello, char[]={a,b,c} ... bye ]";
int indexOfOpenBracket = i.indexOf("[");
int indexOfLastBracket = i.lastIndexOf("]");
System.out.println(i.substring(indexOfOpenBracket+1, indexOfLastBracket));
Prints:
hello, char[]={a,b,c} ... bye
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With