| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Thu Jul 03, 2008 7:36 pm Post subject: Filter unwanted strings |
|
|
I searched a lot, but it haven't worked out yet....
I want to filter out all the characters wich aren't alphabetic character or numbers.
| Code: |
string := Y#$*&a#^&@y*1
Do something
MsgBox %stringfiltered%
And it shows Yay1
|
|
|
| Back to top |
|
 |
garry
Joined: 19 Apr 2005 Posts: 1083 Location: switzerland
|
Posted: Thu Jul 03, 2008 7:54 pm Post subject: |
|
|
exist sure an easier way but it works (used ASCII codes)
used in Embed TV example
http://www.autohotkey.com/forum/viewtopic.php?t=27264
| Code: | ;---------- remove special characters from string ----------------------
autotrim,off
AAA = Y#$* &a#-^&@y_*1
new2=
Loop,Parse,AAA
{
A:=(Asc(A_LoopField))
B:=chr(a)
if (B="_" OR B=" " OR B="-") ;allow some characters like _- and space when autotrim is off
Goto,SKIP8
if ((a<48 or a>57) AND A<65 OR A>90 AND A<97 OR A>122)
continue
SKIP8:
new2=%new2%%b%
}
msgbox,%new2%
return
|
|
|
| Back to top |
|
 |
Guest
|
Posted: Thu Jul 03, 2008 7:58 pm Post subject: |
|
|
Thx, thats what i needed  |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6084
|
Posted: Thu Jul 03, 2008 8:21 pm Post subject: |
|
|
| Quote: | | I want to filter out all the characters wich aren't alphabetic character or numbers. |
Could be done in one line with RegEx*(), though I do not know how
| Code: | MsgBox, % alnum( "Y#$*&a#^&@y*1" )
alnum( str ) {
loop, parse, str
If a_loopField is alnum
rstr .= a_loopfield
return rstr
} |
 _________________
 |
|
| Back to top |
|
 |
Red Hat Boy
Joined: 10 Apr 2008 Posts: 113
|
Posted: Thu Jul 03, 2008 8:27 pm Post subject: |
|
|
| Code: | InputBox, iString, String Check, Type in a string to be filtered.
FilterList := "@#$%^&*()"
fLen := StrLen(FilterList)
loop
{
StringMid, StopThis, FilterList, %A_Index%, 1
StringReplace, iString, iString, %StopThis% ,,All
if A_Index >= %fLen%
break
}
Msgbox %iString% | That's what I came up with. _________________ I slit the sheet, the sheet I slit,
and on the slitted sheet I sit. ;~} |
|
| Back to top |
|
 |
Oberon
Joined: 18 Feb 2008 Posts: 458
|
Posted: Thu Jul 03, 2008 8:29 pm Post subject: |
|
|
| Code: | | stringfiltered := RegExReplace(string, "\W") |
|
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6084
|
Posted: Thu Jul 03, 2008 8:32 pm Post subject: |
|
|
 _________________
 |
|
| Back to top |
|
 |
Razlin
Joined: 05 Nov 2007 Posts: 417 Location: canada
|
Posted: Thu Jul 03, 2008 8:33 pm Post subject: |
|
|
Gotta love the power of regex. _________________ -=Raz=- |
|
| Back to top |
|
 |
garry
Joined: 19 Apr 2005 Posts: 1083 Location: switzerland
|
Posted: Thu Jul 03, 2008 8:49 pm Post subject: |
|
|
aargghh, one line, I knew it's possible with regex
thank you all for the examples above |
|
| Back to top |
|
 |
|