I have a string in which :
occurs several times. I want each occurance of :
to be surrounded by double quotes, like ":"
without truncating the data around it.
I have tried to use String.replaceAll(":", "\":\"");
but it truncates the characters around :
.
How can I enclose all occurances of :
by "
without truncating the characters around :
?
EDIT:-
My String:-
{key1:value1,key2:value2,key3:{key4:value4,key5:value5,key6:{key7:{key8:value8}}},key9:value9}
More readable Form:-
{
key1:value1,
key2:value2,
key3:{
key4:value4,
key5:value5,
key6:{
key7:{
key8:value8
}
}
},
key9:value9
}
What I am doing:-
responseString = responseString.replaceAll(":", "\":");// Put " before each occurance of :
responseString = responseString.replace(":[^\\Q{\\E]", ":\""); // Put " after each occurence of : except the ones preceded by {
Output:-
{key1":"alue1,key2":"alue2,key3":{key4":"alue4,key5":"alue5,key6":{key7":{key8":"alue8}}},key9":"alue9}