Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Remove empty and non-alpha chars in string?
Message
From
11/01/2003 11:02:12
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
11/01/2003 10:53:38
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00740604
Message ID:
00740633
Views:
26
>>>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), ";"),', ',';;')

That would be simpler, if I care about duplicate delimiters. But as I said, I have to check for duplicate delimiters anyway, since the user can press a double space, for instance.

>PS: strtran(lcText, ", " + chr(13) + chr(10), ";;;;")
>
>would do the conversion only if it finds 4 chars and in that order.
>Cetin

Yes, I meant to use chrtran() here, but used the wrong command for the simplified version.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform