cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for removing special character ( ' ) from a string

Former Member
0 Kudos

Hi All,

Can anybody provide me an UDF to remove the special character i.e., ' from a string. Your help is highly appreciated.

Ex: Source field contains the values as ABC'S then in target field value as ABCS.

Regards

Faisal

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor

Hi,

Try using standard text function replaceString()


             Input ------->
            Constant(')-->  replaceString() ----->target
            Constant()--->

Regards

Anupam

Answers (4)

Answers (4)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

If your requirement is just to remove single special character like ( ' ) then you can use Standard function replaceString itself. You basically need to provide three inputs to the function. one from the source, second delimiter in this case ' using constant and another constant with empty space. Already Anupam explained it. If you have multiple delimiter pattern and unpredictable data that comes from the source then better go for the UDF.

Former Member
0 Kudos

Hi,

UDF is not required for this.

You can use standard text function replaceString to achieve your requirement.

Regards

Ramesh

Former Member
0 Kudos

Hi,

by writting small UDF you can remove special character.

public static String removeSpecialChar(String s)

{

try

{

int i,j;

String a="";

String stringSet[]={"ABC'S"};

for(i=0;i<stringSet.length;++i)

{

j=s.indexOf(stringSet<i>);

while(j>=0)

{

a=s.substring(0,j);

a=s.substring(stringSet<i>.length()j);

s=a;

j=s.indexOf(stringSet<i>);

}

}

}

catch(Exception e)

{

e.printStackTrace();

}

return s;

}

regards,

ganesh.

PriyankaAnagani
Active Contributor
0 Kudos

Hi,

Please try with below logic...

UDF:

String result = "";

String[] splt;

delimiter = "'"; //special character to be removed

splt = input.split(delimiter);

for(int i =0; i < splt.length ; i++)

result = result + splt(i);

Regards,

Priyanka