Skip to Content
Author's profile photo Asgar Ali MK

Function to Remove special characters from a word and convert non English letter to English letter based on the ASCII value

This function will help you to remove all special characters from a word expect space .The output will contains only the alphabets a-z A-Z and space. The other characters and number will be removed from the word. It also help you to convert non English word into corresponding English word based on the ASCII values. Please find below given example. ÀÁÂÄÃÅ are non English(Latin) characters will convert into corresponding English character A.

  1. e.g. ÀŠGÄR@# to ASGAR And àšgär()\/ to asgar

Please find below code.

#$LV_OUTPUT_WORD : Output Word after convertion.

#$LV_LNGH_WORD : To get the characters one by one.

#$GV_SNGL_LETTER : Each character of a word.

#$P_INPUT_WORD : Input Word passed using this parameter.

$LV_OUTPUT_WORD = NULL;

$LV_LNGH_WORD = 1;

WHILE ($LV_LNGH_WORD <= length($P_INPUT_WORD))

BEGIN

$GV_SNGL_LETTER=SUBSTR ($P_INPUT_WORD,$GV_LNGH_WORD,1);

IF((ASCII( $GV_SNGL_LETTER) >= 65 AND ASCII( $GV_SNGL_LETTER) <= 90 ) OR (ASCII( $GV_SNGL_LETTER) = 32 ) OR (ASCII( $GV_SNGL_LETTER) >= 97 AND ASCII( $GV_SNGL_LETTER) <= 122))

BEGIN

$GV_SNGL_LETTER = $GV_SNGL_LETTER;           

END

ELSE IF((ASCII( $GV_SNGL_LETTER) >= 210 AND ASCII( $GV_SNGL_LETTER) <= 214) OR ASCII($GV_SNGL_LETTER) = 216)

BEGIN

$GV_SNGL_LETTER = CHR(79);  

END

ELSE IF(ASCII( $GV_SNGL_LETTER) >= 242 AND ASCII( $GV_SNGL_LETTER) <= 246)

BEGIN

$GV_SNGL_LETTER =  CHR(111);              

END

ELSE IF (ASCII( $GV_SNGL_LETTER) >= 192 AND ASCII( $GV_SNGL_LETTER) <= 197)

BEGIN

$GV_SNGL_LETTER = CHR(65);  

END

ELSE IF (ASCII( $GV_SNGL_LETTER) >= 224 AND ASCII( $GV_SNGL_LETTER) <= 229)

BEGIN

$GV_SNGL_LETTER = CHR(97);  

END

ELSE IF(ASCII( $GV_SNGL_LETTER) >= 200 AND ASCII( $GV_SNGL_LETTER) <= 203)

BEGIN

$GV_SNGL_LETTER = CHR(69);  

END

ELSE IF(ASCII( $GV_SNGL_LETTER) >= 232 AND ASCII( $GV_SNGL_LETTER) <= 235)

BEGIN

$GV_SNGL_LETTER = CHR(101);               

END

ELSEIF(ASCII( $GV_SNGL_LETTER) >= 204 AND ASCII( $GV_SNGL_LETTER) <= 207)

BEGIN

$GV_SNGL_LETTER = CHR(73);  

END

ELSEIF(ASCII( $GV_SNGL_LETTER) >=  236 AND ASCII( $GV_SNGL_LETTER) <= 239)

BEGIN

$GV_SNGL_LETTER = CHR(105);               

END

ELSE IF(ASCII( $GV_SNGL_LETTER) >= 217 AND ASCII( $GV_SNGL_LETTER) <= 220)

BEGIN

$GV_SNGL_LETTER = CHR(85);

END

ELSE IF(ASCII( $GV_SNGL_LETTER) >= 249 AND ASCII( $GV_SNGL_LETTER) <= 252)

BEGIN

$GV_SNGL_LETTER = CHR(117);

END

ELSE IF(ASCII( $GV_SNGL_LETTER) = 241 OR ASCII( $GV_SNGL_LETTER) = 209 )

BEGIN

$GV_SNGL_LETTER = CHR(110);               

END

ELSE IF(ASCII( $GV_SNGL_LETTER) = 199)

BEGIN

$GV_SNGL_LETTER = CHR(67);  

END

ELSE IF(ASCII( $GV_SNGL_LETTER) = 231)

BEGIN

$GV_SNGL_LETTER = CHR(99);  

END

ELSE IF(ASCII( $GV_SNGL_LETTER) = 209)

BEGIN

$GV_SNGL_LETTER = CHR(78);  

END

ELSE IF(ASCII( $GV_SNGL_LETTER) = 241)

BEGIN

$GV_SNGL_LETTER = CHR(110);               

END

ELSE IF(ASCII( $GV_SNGL_LETTER) = 221 OR ASCII( $GV_SNGL_LETTER) = 159)

BEGIN

$GV_SNGL_LETTER = CHR(89);  

END

ELSE IF(ASCII( $GV_SNGL_LETTER) = 253 OR ASCII( $GV_SNGL_LETTER) = 255)

BEGIN

$GV_SNGL_LETTER = CHR(121);               

END

ELSE IF(ASCII( $GV_SNGL_LETTER) = 142)

BEGIN

$GV_SNGL_LETTER = CHR(90);  

END

ELSE IF(ASCII( $GV_SNGL_LETTER) = 158)

BEGIN

$GV_SNGL_LETTER = CHR(122);               

END

ELSE IF(ASCII( $GV_SNGL_LETTER) = 138)

BEGIN

$GV_SNGL_LETTER = CHR(83);  

END

ELSE IF(ASCII( $GV_SNGL_LETTER) = 154)

BEGIN

$GV_SNGL_LETTER = CHR(115);               

END

ELSE IF(ASCII( $GV_SNGL_LETTER) = 131)

BEGIN

$GV_SNGL_LETTER = CHR(102);               

END

ELSE

BEGIN

$GV_SNGL_LETTER = NULL;       

END

$GV_LNGH_WORD = $GV_LNGH_WORD+1;

$GV_OUTPUT_WORD = $GV_OUTPUT_WORD||$GV_SNGL_LETTER;

END

RETURN $GV_OUTPUT_WORD;

This is code that will remove all special characters and convert non English (Latin) word to corresponding English word based on the ASCII value.

Regards

Asgar

Assigned Tags

      12 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Good Content!

      Author's profile photo Anitha G S
      Anitha G S

      Hi Asgar,

      I tried using this function but BODS does not return the right ASCII value for the non English characters. It returns -1 and hence does not get replaced with the nearest equivalent Eng character.

      Is there any language, codepage setting to be done?

      Many thanks,

      Author's profile photo Asgar Ali MK
      Asgar Ali MK
      Blog Post Author

      Hi Anitha,

      Could you please tell me ,which character you want to conver to english.

      Regards

      Asgar

      Author's profile photo Anitha G S
      Anitha G S

      NonEngTxt.png

      Author's profile photo Asgar Ali MK
      Asgar Ali MK
      Blog Post Author

      Hi Anitha,

      ASCII character of first special character is 129 and second is 148.

      Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion.

      You can update above function with these values 🙂

      Regards

      Asgar

      Author's profile photo Anitha G S
      Anitha G S

      Thanks Asgar, but BODS ascii fn is returning -1 for all non Eng chars.

      Author's profile photo Asgar Ali MK
      Asgar Ali MK
      Blog Post Author

      Hi Anitha,

      Just try to do it reverse .

      Print(Chr(129));

      Regards

      Asgar

      Author's profile photo Anitha G S
      Anitha G S

      thanks Asgar, the print returns nothing.

      Author's profile photo Asgar Ali MK
      Asgar Ali MK
      Blog Post Author

      which versio ur using ..BODs version

      Author's profile photo Anitha G S
      Anitha G S

      BODS version is 12.2.3.2

      Author's profile photo Kumari Varsha
      Kumari Varsha

      Dear all,

      I am trying to separate string and want to remove a special character but getting error. Please help me out.

      Input

          Atlas_Id                                                         Sr_id

      X/P01/ZOOMAR UK                        Zoomarine -One of it’s Kind%Ticket Only

      ………                                ……….

      ………..                              ………  

      Output

      Field1          Field2             Filed3                                 Sr_id

        X                  PO1            ZOOMAR UK                   Zoomarine One of its Kind Ticket Only

      Regards

      Varsha

      Author's profile photo Asgar Ali MK
      Asgar Ali MK
      Blog Post Author

      Hi varsh,

      For separate string use word_ext() function

      To remove special character find out ascii code of corresponding character and convert it to normal english ascii value

      for example :- ASCII of â 225 and corresponding english character a have ascii value 97

      use below link to get ascii values

      ASCII Code - The extended ASCII table

      Regards

      ASgar