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
sml9099sml9099 

Split function not working as desired

Hi All, 
I am using split function and new line character to split the long text area field and show them in different lines. It is working fine but it is also adding parentheses around every text in new line. I don't want them to add parentheses around every text. Below is my code.

rEntry.Publisher_URLs__c += ' ' + rC.publisher_Site_Placement_URL__r.Name.split('\n') + ';';

Output:
(sportsgroundgames.com); (womenshealthbase.com); (wwe.com);

Desired Output:
sportsgroundgames.com; womenshealthbase.com; wwe.com;

Can someone help me in removing parentheses. Thanks is advance.
 
Best Answer chosen by sml9099
MithunPMithunP
Hi sml9099,

I have tested that code in my org's developer console, it's working perfect.

do one thing add replaceAll method after splitting
//Keep old code as it is
rEntry.Publisher_URLs__c += ' ' + rC.publisher_Site_Placement_URL__r.Name.split('\n') + ';';

//You just add below line after your loop where you want to see out put

rEntry.Publisher_URLs__c = rEntry.Publisher_URLs__c.replaceAll('[\\()]', '')
Best Regards,
Mithun.


 

All Answers

MithunPMithunP
Hi sml9099,

Use replaceAll method.
 
rEntry.Publisher_URLs__c += ' ' + rC.publisher_Site_Placement_URL__r.Name.split('\n').replaceAll("\\(", "").replaceAll("\\)","") + ';';

Best Regards,
Mithun.
sml9099sml9099
Hi Mithun, 

Thanks for your reply. I used the above and I am getting this error.

Compile Error: line 29:97 no viable alternative at character '"' at line 29 column 97.

Then I replaced double qoutes with single quotes , it is still not working. Please Advice.

Thanks
sml9099sml9099
This is the code I used with single quotes.
rEntry.Publisher_URLs__c += ' ' + rC.publisher_Site_Placement_URL__r.Name.split('\n').replaceAll('\\(', '').replaceAll('\\)','') + ';';

and below is the error.

Compile Error: Method does not exist or incorrect signature: [List<String>].replaceAll(String, String) at line 29 column 87

Your help will be highly aprreciated.

Thanks
 
MithunPMithunP
Hi sml9099,

Here is exact solution.
rEntry.Publisher_URLs__c += ' ' + rC.publisher_Site_Placement_URL__r.Name.split('\n').replaceAll('[\\()]', '') + ';';
Best Regards,
Mithun.

 
sml9099sml9099
Hi, 

Still the same error 

Method does not exist or incorrect signature: [List<String>].replaceAll(String, String) at line 29 column 87
MithunPMithunP
Hi sml9099,

I have tested that code in my org's developer console, it's working perfect.

do one thing add replaceAll method after splitting
//Keep old code as it is
rEntry.Publisher_URLs__c += ' ' + rC.publisher_Site_Placement_URL__r.Name.split('\n') + ';';

//You just add below line after your loop where you want to see out put

rEntry.Publisher_URLs__c = rEntry.Publisher_URLs__c.replaceAll('[\\()]', '')
Best Regards,
Mithun.


 
This was selected as the best answer
sml9099sml9099
It worked. Thanks a lot. Really apreciate your help
MithunPMithunP
Perfect. Finally it worked :)

Best Regards,
Mithun.