Mega Code Archive

 
Categories / Delphi / Strings
 

How can i remove non Alpha characters from a string

Title: How can i remove non Alpha characters from a string Question: In arabic language user can type strings with special characters that are not part from alphabet how can i remove those special characters ? Answer: In arabic language user can type strings with special characters that are not part from alphabet how can i remove those special characters ? using isCharAlpha function from the win32 API that test if a caharacter is part from Alphabet or none we can test all characters of a string and return a string containing only alphabet characters, this is useful in Arabic language to trim kashida characters funtion RemoveNonAlpha(srcStr : string) : string; var i : integer; begin result:=''; for i:=0 to length(srcStr)-1 do if isCharAlpha(srcstr[i]) then result:=result+srcStr[i]; end