Delete all the special characters from a string

How can be deleted all the special characters contained in a string? I have used (DELCHR(String,’=’,’!’):wink: to delete one char, likewise I need to delete more than one char. Can anyone please share your experience if you had come across with the similar requirement? I would highly appreciate if you can suggest some workaround to manage this issue.

Thanks in advance,

Jithin Mathew.

Sorry Dear All…I got the solution. We can use below coding

(DELCHR(String,’=’,’!|@|#|$|%’);

Technically there a ton more possible “special characters” so you can define the characters you DO want to keep

Like this

txtCharsToKeep := ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’;
“My Field” := DELCHR(“My Field”,’=’,DELCHR(“My Field”,’=’,txtCharsToKeep));

It will remove all chars you didn’t specify

static void removeWS(Args _args)

{

//This code will remove all the special characters as well as trim the string… :slight_smile:

str string1,appendstr,ch;

int k,i,len;

;

string1= strupr(" Ganesh @%@^!*Sahane ");

k= strlen(string1);

for (i=1;i<=k;i++)

{

ch = substr(string1,i,1);

if(char2num(ch,1) >= 65 && char2num(ch,1)<=90)

{

appendstr += ch;

}

}

len=strlen(appendstr);

//info(strfmt(len));

info(strfmt(“append str Length is : %1 & New String is : %2”,len,appendstr));

}

so efficient!
if I need to keep 0,1,2…9, I’ll extend txtCharsToKeep, to become: txtCharsToKeep := ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789’; am I correct?

Yes

It takes the string and removes all the chars you want to keep. Which leaves you with all the chars you want to get rid of. Then it uses that string to remove those chars from the original string. Which finally gives you want you were looking for.

We find it useful when importing data from other systems. Sometime certain fields can have different formats like phone numbers

123-456-7890

(123) 456-7890

So we prefer saving it as a number string only

yes, you have to include small letters also in txtCharsToKeep to keep them in your field…

Hello,

Can you please suggest me if I only require a numberic value then what i need to do.

i do want to remove the spaces between the strings is it possible or not??

I want to remove the spaces from the string if any…!! Is it possible using the same above code ??

Please try this code : DELCHR(String,‘=’,’ ');

Rgds,

JITHIN.

If you wanted to retain only numeric characters in your string, then give only numeric values in ‘txtValuesToKeep’.

Thanks,

Jithin

Hi,

I want to delete “
” with in the String how it is possible.

I have already solved the problem regarding my issue. anyways thanks for the reply.

Pls try below mentioned code:

Len:=STRLEN(‘br’);
POS:=STRPOS(MyText,‘br’);
WHILE POS>0 DO BEGIN
MyText:=DELSTR(MyText,POS,Len);
POS:=STRPOS(MyText,‘br’);
END;
MESSAGE(MyText);

HI,

If you want to delete the special characters from string, you can use “strAlpha” function. This copies only the alphanumeric characters from a string.

Ex : info(strFmt("%1", strAlpha("?a*b!!!cD123.")));
results in “abcD123”.

I hope this helps :slight_smile:

Hi,

Please how can i delete accents from characters ? for example a customer from France his address in containing characters like (à, â, é, ç…) for example!
any idea please.