Split function on [16]
I'm trying to split the data from the variable as given below:
string data = [16]
string [] temp = null
temp.split("\\[");
开发者_Python百科
I am struck here, how do I split two square brackets and get values 16?
I'm not sure whether you want the String "16" or the Integer 16, so I've shown both below
String data = "[16]"
assert "16" == data[1..-2]
assert 16 == data[1..-2].toInteger()
FYI, the code above will work for a String of any length enclosed in []
A little bit of research gave me this option to replace all square brackets
string.replaceAll("\\[|\\]","");
Any other suggestions are welcome
Thanks
精彩评论