Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Clear control codes from string
Message
De
20/12/2003 03:02:38
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00860937
Message ID:
00860946
Vues:
88
>An editbox allows my user to enter a sring. The user may enter a control code, like a CRLF, which is not desired in the string.
>
>Right now to clear these codes, my project calls a fuction to loop through the string:
>
FOR c=1 TO LEN(lcCommand)
>IF ASC(SUBSTR(lcCommand,c,1))<32 or ASC(SUBSTR(lcCommand,c,1))>122
>   lcCommand=STUFF(lcCommand,c,1," ")
>ELSE
>ENDIF
>ENDFOR
>RETURN ALLTRIM(lcCommand)
>
>Is there an inline fuction that would be more appropriate?

Terry, create a string of allowed chars then use CHRTRAN() to remove them from the source string which results in all disallowed chars. Then pass this again using CHRTRAN() to the original string to remove them:
cOrgString = "whatever text with some control chars"
cAllowedChars = "abcdefghijklmnopqrstuvwxyz0123456789"

cCleanString = CHRTRAN( cOrgString, CHRTRAN( cOrgString, cAllowedChars, "" ), "" )
In the End, we will remember not the words of our enemies, but the silence of our friends - Martin Luther King, Jr.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform