Quantcast
Channel: SCN : All Content - Data Services and Data Quality
Viewing all articles
Browse latest Browse all 4013

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

$
0
0

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


Viewing all articles
Browse latest Browse all 4013

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>