简体   繁体   中英

replace string in double quotes - java

I am reading a file and storing into a string variable input :

"returnonassets":{"content":"5.97%","term":"ttm"},"float":"332400000","ex_dividenddate":"dec 27, 2013","payoutratio":"23.00%","qtrlyearningsgrowth":{"content":"8.90%","term":"yoy"}

I want to replace "float":"332400000" to "floatShare":"332400000" , i tried following commands but didnt worked :

input.replaceAll("\"float\"", "\"floatShare\"");

Edit:

this is my append command to StringBuilder sb:

sb.append(input.toString().replaceAll("-", "").replaceAll("\"float\"", "\"floatShare\"").toLowerCase()).append("\n");

Strings in Java are immutable. The way your code is at the moment, you are getting a new string object from input.replaceAll("\\"float\\"", "\\"floatShare\\""); , but not doing anything with it. Solving the problem is simple. Instead of doing:

input.replaceAll("\"float\"", "\"floatShare\"");

do

input = input.replaceAll("\"float\"", "\"floatShare\"");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM