+ Start a Discussion
kumar.fdc81.3902978579608325E12kumar.fdc81.3902978579608325E12 

I need to remove Special characters and display string

Hi all,

I don't want to display special character in a field.
suppose i have one field in that field values are : A & B
But I need output  A and B like this.
I created a class but it's not working Please help me.

public class CommonFunctions {
    public void RemovingSpecialCharacters(){
        List<case> listcase = new  List<case>();
        String specialCharacters = '&';
        if(listcase.Notes__c.Contains('/&')){
            listcase.Notes__c = 'And';
            }        
    }
}
Best Answer chosen by kumar.fdc81.3902978579608325E12
ManojjenaManojjena
Hi Kumar ,

can you tell me the line number from which you are getting error .

Please check below code in console it is working .
 
String str='MANOJ&SAROJ';
String strr=str.replace('&','and');
System.debug(strr);

Thanks 
Manoj

All Answers

ManojjenaManojjena
Hi Kumar,

You need to remove only & with And ?
kumar.fdc81.3902978579608325E12kumar.fdc81.3902978579608325E12
Hi Manoj,

I need to Remove & after i need to add AND.

Thanks
ManojjenaManojjena
HI Kumar ,

Try with below code it will help ,

I have used replace method of string class ,which takes two parameter first once which wnat to replace second one which you wnat to replace with .
 
public class CommonFunctions {
    public void RemovingSpecialCharacters(){
        List<case> listcase = new  List<case>();
         if(listcase.Notes__c.Contains('&')){
            listcase.Notes__c.replace('&','And'); 
            }        
    }
}

Let me know any issue 

Thnaks 
Manoj
kumar.fdc81.3902978579608325E12kumar.fdc81.3902978579608325E12
This error coming
Initial term of field expression must be a concrete SObject: List&lt;Case&gt;
boBNunnyboBNunny
Try the below.  As long as it's not over 32K, it should work.

public class CommonFunctions {

    public void RemovingSpecialCharacters(){
         List<case> listcase = new  List<case>();
         if(string.valueOf(listcase.Notes__c).Contains('&')){
            listcase.Notes__c = string.valueOf(listcase.Notes__c).replace('&','And');
         }       
   }
}
kumar.fdc81.3902978579608325E12kumar.fdc81.3902978579608325E12
Hi boBNunny,
I am getting same above error.
Thanks
 
ManojjenaManojjena
Hi Kumar ,

can you tell me the line number from which you are getting error .

Please check below code in console it is working .
 
String str='MANOJ&SAROJ';
String strr=str.replace('&','and');
System.debug(strr);

Thanks 
Manoj
This was selected as the best answer
boBNunnyboBNunny
You should put the specific code in developer console and then give the debug for the specific line in question.  I just did it with the below, and it works fine.  What kind of field is "notes__c"?

LIST<Case> caseLIST = [select ID, Description from Case LIMIT 1];
caseLIST[0].Description = string.valueOf(caseLIST[0].Description).replace('&', 'And');
system.debug(caseLIST);
kumar.fdc81.3902978579608325E12kumar.fdc81.3902978579608325E12
Thanks Manoj..
prashant singh 169prashant singh 169
you can use regular expression to remove the Special characters