java - Need to remove extra square brackets in the string -


static arraylist<string> coordinates = new arraylist<string>(); static string str = ""; static arraylist scribbles = new arraylist();  coordinates.add("string placed, string not placed"); string codchange = coordinates.tostring().replaceall(", ", ""); stringbuffer sb = new stringbuffer(codchange); sb.insert(1,"m "); arraylist alistnumbers = new arraylist(arrays.aslist(sb.tostring())); system.out.println("coordinates: " + alistnumbers.tostring().replaceall("\\[|\\]", ""));                 scribbles.add(alistnumbers); str = scribbles.tostring(); system.out.println("string: " + str); 

output:

coordinates: m string placedstring not placed string: [[m string placedstring not placed]] 

i want string: appear single square brackets like:

string: [m string placedstring not placed] 

since there 2 different replacement required.

use below code

string s = "[[m string placedstring not placed]]"; system.out.println(s.replaceall("[[","[").replaceall("]]","]"); 

if sure exact position of [[ @ beginning , ]] @ end, use substring suggested in other answer in same answer thread.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -