You need to sign in to do that
Don't have an account?
Removing multi Spaces in a Text Area
I have two fields one with Rich text Area and other is long Text area. I have Trigger which removes all the HTML tags of Rich Text Area and stores in Long Text Area. Now my Text is generated with multiple spaces. So I tried with
result = result.replaceAll('\\s+',' ');
result = result.replaceAll(' ',' ');
result = result.replaceAll(' ',' ');
But this did not solve my problem. Is there any other solution to remove multi spaces between my text.
trigger UpdateSearsDescriptionFieldUpdate on ECS__Product__c (before insert, before update) {
for(ECS__Product__c pro : Trigger.new){
if(pro.ECS__Description__c != null && pro.ECS__Description__c != ''){
string result = pro.ECS__Description__c.replaceAll('<br/>',' ');
System.debug('pro.ECS__Description__c-----:'+pro.ECS__Description__c);
System.debug('result-----:'+result); result = result.replaceAll('<br />',' ');
System.debug('result-----:'+result); string HTML_TAG_PATTERN = '<.*?>';
System.debug('HTML_TAG_PATTERN-----:'+HTML_TAG_PATTERN);
pattern myPattern = pattern.compile(HTML_TAG_PATTERN);
System.debug('myPattern-----:'+myPattern);
matcher myMatcher = myPattern.matcher(result);
System.debug('myMatcher-----:'+myMatcher);
result = myMatcher.replaceAll('');
System.debug('result-----:'+result);
result = result.replaceAll('<br>','');
System.debug('result-----:'+result);
result = result.replaceAll('<','');
System.debug('result-----:'+result);
result = result.replaceAll('>','');
result = result.replaceAll('&','&');
result = result.replaceAll(''','\'');
result = result.replaceAll('\\s+',' ');
System.debug('result before replace-----:'+result);
result = result.replaceAll(' ',' ');
System.debug('result-----:'+result);
result = result.replaceAll(' ',' ');
System.debug('result-----:'+result);
if(result.length() > 2400) {
result = result.substring(0, 2400);
}
pro.Sears_com_Description__c = result;
System.debug('pro.Sears_com_Description__c-----:'+pro.Sears_com_Description__c);
}
}
}
This is my code. Sears_com_Description__c is Long Text area and ECS__Description__c is Rich Text Area.
Thanks,