Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Remove empty and non-alpha chars in string?
Message
De
11/01/2003 10:53:38
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
11/01/2003 10:33:05
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00740604
Message ID:
00740631
Vues:
28
>>Hmmm... this is something I got to analyze carefully, for I feel I got plenty to learn here... ;)
>>Thank you both Çetin and Hilmar.
>>Ulises
>
>I learned something here, too. In Bata-Bolivia, I let the users type text into an EditBox, using several alternative characters as separators (new-line; comma; semicolon [punto y coma]; or space). To convert this to a single separator, I repeatedly used StrTran() (search and replace). I just realized today that a single call to ChrTran() can replace a whole series of StrTran()!
>
>Something like this:
>
>
>* Inefficient, old method:
>lcText = strtran(lcText, ",", ";")
>lcText = strtran(lcText, " ", ";")
>lcText = strtran(lcText, chr(13), ";")
>lcText = strtran(lcText, chr(10), ";")
>
>* Much simpler:
>lcText = strtran(lcText, ", " + chr(13) + chr(10), ";;;;")
>
>
>Note: in the above example, chr(13) + chr(10) will translate to two delimiters, but I have to get rid of repeated delimiters anyway, in case the user types two or more spaces in a row, or leaves a space at the end of the line. This latter part, I believe, is still best done with strtran().
>
>Hilmar.

Hilmar,
Wouldn't 'much simplier' part be :
lcText = chrtran(lcText, ", " + chr(13) + chr(10), ";;;;")

You could translate chr(13)+chr(10) with strtran and apply chrtran to result :

lcText = chrtran(strtran(lcText,chr(13) + chr(10), ";"),', ',';;')

or just a pure chrtran solution is possible (provided each chr(13) is followed by a chr(10)) :

lcText = chrtran(lcText,', '+ chr(10) + chr(13),';;;') && Discard all chr(13)

PS: strtran(lcText, ", " + chr(13) + chr(10), ";;;;")

would do the conversion only if it finds 4 chars and in that order.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform