You need to sign in to do that
Don't have an account?
mariappangomathiraj
Problem in Replace in string Method
String Names = '^Community$|^Luxury$|^Golf$|^Course$|^Hospitality$|^Industrial$|^';
My Code:
Names = (Names!= '' && Names!= null) ? Names.replaceAll('\\$|^,'') : '';
system.debug(Logginglevel.Info,'::::Names::::::::::'+Names);
Current output in Debug Log:
^Community$|^Luxury$|^Golf$|^Course$|^Hospitality$|^Industrial$|^Industrial$|
Expected Output:
Community,Luxury,Golf,Course,Hospitality,Industrial
Use ResEx in replaceall function like below
Names = (Names!= '' && Names!= null) ? Names.replaceAll('[$|^]','') : '';
All Answers
Use ResEx in replaceall function like below
Names = (Names!= '' && Names!= null) ? Names.replaceAll('[$|^]','') : '';
I have tried your code, It gives following output :
CommunityLuxuryGolfCourseHospitalityIndustrial
Hi,
try following, It may help you.
String Names = '^Community$|^Luxury$|^Golf$|^Course$|^Hospitality$|^Industrial$|^';
Names = (Names!= '' && Names!= null) ? Names.replace('$|^',',') : '';
Names = (Names!= '' && Names!= null) ? Names.replace('^','') : '';
system.debug('::::Names::::::::::'+Names);
I got followimg output :
Community,Luxury,Golf,Course,Hospitality,Industrial,
We can not get your required out put in one step.
Try below code for exact output what you want to get.
String Names = '^Community$|^Luxury$|^Golf$|^Course$|^Hospitality$|^Industrial$|^';
if(Names!= '' && Names!= null)
{
Names = Names.remove('^') ;
names = names.remove('$');
names = names.replace('|',',');
names = names.removeEnd(',');
system.debug(Logginglevel.Info,'::::Names::::::::::'+Names);
}else
names='';