You need to sign in to do that
Don't have an account?
Narayana Reddy 30
I have a requirement to split the string based on delimeter, compare the tokens with specific value and if it finds a match, clear that specific value . Example 1 : string 'test,krishna,shekhar, karjun' need to be split base
I have a requirement to split the string based on delimeter, compare the tokens with specific value and if it finds a match, clear that specific value or replace it with other value .
Example 1 : string 'test,krishna,shekhar, karjun' need to be split based on comma (,) and compare each value with word 'shekhar', since match is found clear the word shekhar from original string . So the updated string value will be ''test,krishna,karjun' ( Shekhar is removed including delimeter )
Can you plesae suggest the best way to achieve this rquirement ?
Example 1 : string 'test,krishna,shekhar, karjun' need to be split based on comma (,) and compare each value with word 'shekhar', since match is found clear the word shekhar from original string . So the updated string value will be ''test,krishna,karjun' ( Shekhar is removed including delimeter )
Can you plesae suggest the best way to achieve this rquirement ?
You'll want to explore String.split, List.indexOf, List.remove and String.join class methods.
It is a real requirement. Can you please add sample code ?
I have a requirement to replace specific text separated by a delimeter (delimeter can be , : ; etc). Example 1 : In string 'Sonu,krishna,Siva, pintoo' , need to replace specific token/text "Pintoo" , resultant string value will be 'Sonu, Krishna,Siva' . Example 2 : In string 'Padma;Rama;Lakshmi;Aruna;Usha', replace specific token 'Rama' , resultant string value will be 'Padma;Lakshmi;Aruna;Usha' ( Removed token Rama)
I tried it via split() method and rejoining the string etc, however looking for if there is any simplest way to get this done
This can be done using the some string class methods. Here is the below solution of your problem.
String s1 = 'shekhar,test,krishna,shekhar,karjun,shekhar';
if(s1.containsIgnoreCase('shekhar,')){
s1=s1.replace('shekhar,','');
}
s1=s1.removeEnd(',shekhar');
system.debug(s1);
If the solution is helpul to you, Please mark it as a best answer.
Thanks
Kapil Sharma