On Friday, 21-September-2007 at 15:45:16 Kai Peters wrote,
>
>Hi ~
>
>what is a very fast way to remove all non-numerical characters from
>a given string? I will have to process almost a million of these, so speed
>matters.
>
>I.e., "(250) 764-0929" -> "2507640929"
I'm not sure how fast this would compare to other methods, but give it a go...
First, create a string containing all characters, less the ten numerals...
chrs: ""
repeat n 256 [append chrs to-char n - 1]
chrs: exclude chrs "1234567890"
Then trim your strings thus...
trim/with "(250) 764-0929" chrs
Hmmm. Well - it might work, depending on the type of characters in your
string. It works on your example, but not on a string made up of random
characters. Can anyone explain if that's expected behaviour? ie...
>> chrs: ""
== ""
>> repeat n 256 [append chrs to-char n - 1]
== [EMAIL PROTECTED]
^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^!^_ !"#$%&'()*+,-./0123456789:;<=>[EMAIL
PROTECTED]
>> chrs: exclude chrs "1234567890"
== [EMAIL PROTECTED]
^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^!^_ !"#$%&'()*+,-./:;<=>[EMAIL
PROTECTED]|}~^~...
>> str: ""
== ""
>> loop 1000 [append str to-char random 255]
== [EMAIL
PROTECTED]@ãW^Sw¸FÃñ^_3»þóâÅæ®å¤8^H±û±^\aÑÐV^N·ûÐÕWujá)°V^CìÇáùÄ^~ì×^\íÑ%Ð^B'...
>> trim/with "(250) 764-0929" chrs
== "2507640929"
>> trim/with str chrs
==
{ëy8èfåñm4úñãwñ3þóâæå8ûaûujáìáùìíòùõfûétðýâÿ0ééiõñltp9wöòòêólneîçgnòxðsür2luíþþbë3òëì1óáøhèaãìþl3uyoczÿbqnçbrðly5yÿesvîôa4...
???
-- Carl Read.
--
To unsubscribe from the list, just send an email to
lists at rebol.com with unsubscribe as the subject.