function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Fe PradellaFe Pradella 

ReplaceAll with Brackets

Hi all!

I'm trying to replace an information with [ from JSON (String)..
From:
 "name":[    

To:
"name_list":[ 

I tried couple like:

sResp = SResp.replaceAll('\"name\":\\[', '\"name_list\":\\[');

Nothing seems to work since I cannot get this list after during the execution.

Thanks!!
Valentin F.Valentin F.
Hi Fe,

The replaceAll(String regExp, String replacement) method replaces each substring of a string that matches the regular expression regExp with the replacement sequence replacement (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm).
You should better use the replace(String target, String replacement) method.
For each occurence of the target, the replacement will be used.
sResp = SResp.replace('\"name\":\\[', '\"name_list\":\\[');
Let me know if it helped you.
Have a good day,
Valentin
 
Fe PradellaFe Pradella
It's still ignoring my string. sResp = sResp.replace('\"name\": \\[', '\"name_list\": \\['); //>>> from: "name": [ to: "name_list": [
Valentin F.Valentin F.
Hi Fe,

Could you show more of your code or at least an example of it ?
Have you tried to debug the execution and the results ?
Fe PradellaFe Pradella
I have a string and I need to replace an information: from: "name: " [ to: "name_list" [ I was facing problem regarding which information use in replace. I got it solved using: sResp = sResp.replace('\"name\": [', '\"name_list\": [');