AutoHotkey Community

It is currently May 26th, 2012, 8:44 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Filter unwanted strings
PostPosted: July 3rd, 2008, 7:36 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 3rd, 2008, 7:54 pm 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 3rd, 2008, 7:58 pm 
Thx, thats what i needed :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 3rd, 2008, 8:21 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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     
}


:)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 3rd, 2008, 8:27 pm 
Offline

Joined: April 10th, 2008, 10:08 pm
Posts: 111
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. ;~}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 3rd, 2008, 8:29 pm 
Offline

Joined: February 18th, 2008, 8:26 pm
Posts: 442
Code:
stringfiltered := RegExReplace(string, "\W")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 3rd, 2008, 8:32 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
:D

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 3rd, 2008, 8:33 pm 
Offline

Joined: November 5th, 2007, 7:25 pm
Posts: 454
Location: canada
Gotta love the power of regex.

_________________
-=Raz=-


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 3rd, 2008, 8:49 pm 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
aargghh, one line, I knew it's possible with regex :)
thank you all for the examples above


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: kkkddd1, sjc1000, Yahoo [Bot] and 59 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group