AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Filter unwanted strings

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Thu Jul 03, 2008 7:36 pm    Post subject: Filter unwanted strings Reply with quote

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

PostPosted: Thu Jul 03, 2008 7:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
Guest






PostPosted: Thu Jul 03, 2008 7:58 pm    Post subject: Reply with quote

Thx, thats what i needed Smile
Back to top
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Thu Jul 03, 2008 8:21 pm    Post subject: Reply with quote

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 Sad

Code:
MsgBox, % alnum( "Y#$*&a#^&@y*1" )

alnum( str ) {
 loop, parse, str
  If a_loopField is alnum
    rstr .= a_loopfield
return rstr     
}


Smile
_________________
Back to top
View user's profile Send private message
Red Hat Boy



Joined: 10 Apr 2008
Posts: 113

PostPosted: Thu Jul 03, 2008 8:27 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Oberon



Joined: 18 Feb 2008
Posts: 458

PostPosted: Thu Jul 03, 2008 8:29 pm    Post subject: Reply with quote

Code:
stringfiltered := RegExReplace(string, "\W")
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Thu Jul 03, 2008 8:32 pm    Post subject: Reply with quote

Very Happy
_________________
Back to top
View user's profile Send private message
Razlin



Joined: 05 Nov 2007
Posts: 417
Location: canada

PostPosted: Thu Jul 03, 2008 8:33 pm    Post subject: Reply with quote

Gotta love the power of regex.
_________________
-=Raz=-
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1083
Location: switzerland

PostPosted: Thu Jul 03, 2008 8:49 pm    Post subject: Reply with quote

aargghh, one line, I knew it's possible with regex Smile
thank you all for the examples above
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group