This is a 'very simple' snippet that allows you to strip everything from a string, but the numbers.
Use: $filter_num(string)
For example: $filter_num(abc123kaljsdflkjdsfkljaslkjsda456lakjdflksadj7kalsdkoi8kljadsflkjdsa9)
Will return: 123456789
alias filter_num {
var %i = $1-, %c = 1, %t = $mid(%i,1,0), %h, %r
while (%c <= %t) {
%h = $mid(%i,%c,1)
if (%h isnum) %r = %r $+ $mid(%i,%c,1)
inc %c
}
return %r
}
I've just always done that out of habbit. I think its something I started doing after reading this from the help file on IF.
The ( ) brackets enclose comparisons, whereas the { } brackets enclose the commands you want to be performed if a comparison is true. You must make sure that the number of ( ) and { } brackets match to make sure that the correct comparisons are made, and that the correct commands are executed.
Using brackets speeds up processing. If an alias uses too few brackets then the statement might be ambiguous and the alias will take longer to parse, might be parsed incorrectly, or might not be parsed at all.
The second half being the part I'm talking about and the speeds up part in particular.
In the end I know were talking milliseconds but hey, a tiny bit more effecient is still more effecient.
Anyways, Zmodem, I forgot to say earlier, good post, we need more posts like this, sure its not the best code on the planet but you saw a problem, coded a solution and posted a working and usefull peice of code that even got a few people talking so they could give you some ideas.
Keep it up man.
Btw, your nickname takes me back like 15 years or so when I was running a wwiv bbs and zmodem was the latest and greatest protocal. Good times. I was such a noob!
Yea, hi 5! But I just figured what the hell. Also I'd have had to add all them other codes, like: !@#$%^&*_-=+;':"><./? and ALL of the ALT+KeyPad combos you can perform, like: æ°Þ¡þ blah blah. Anyhow, thanks.
Yea, good point...
I imagine typo's first one would have worked (assuming he put the backslash before "D"), but for some reason the comments strips backslashes.
Or full on alias
Code:
alias filtering {
if ($isid) {
if ($prop = c) {
var %string $1-, %e 256
while (%e) {
if (($chr(%e) isalpha) || ($chr(%e) isnum)) { %string = $remove(%string, $chr(%e)) }
dec %e
}
return $iif(%string, Results for Characters: %string , No results for Characters.)
}
if ($prop = l) {
var %string $1-, %e 256
while (%e) {
if ($chr(%e) !isalpha) { %string = $remove(%string, $chr(%e)) }
dec %e
}
return $iif(%string, Results for Letters: %string , No results for Letters.)
}
if ($prop = n || !$prop) {
var %string $1-, %e 256
while (%e) {
if ($chr(%e) !isnum) { %string = $remove(%string, $chr(%e)) }
dec %e
}
return $iif(%string, Results for Numbers: %string , No results for Numbers.)
}
}
}
alias filter_numbers {
var %string $1-, %e 256
while (%e) {
if ($chr(%e) !isnum) { %string = $remove(%string, $chr(%e)) }
dec %e
}
return %string
}
alias filter_letters {
var %string $1-, %e 256
while (%e) {
if ($chr(%e) !isalpha) { %string = $remove(%string, $chr(%e)) }
dec %e
}
return %string
}
alias filter_chars {
var %string $1-, %e 256
while (%e) {
if (($chr(%e) isalpha) || ($chr(%e) isnum)) { %string = $remove(%string, $chr(%e)) }
dec %e
}
return %string
}
winner? :P