AutoHotkey Community

It is currently May 27th, 2012, 12:46 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: December 23rd, 2009, 12:11 am 
Offline

Joined: May 26th, 2009, 6:09 am
Posts: 8
Hi

Is there an existing function / script that will convert a text string containing extended characters into a text string that complies with windows filename formating standards?

(I wasn't able to find one by searching the forums)

Thanks
Mike


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 23rd, 2009, 10:06 am 
Offline

Joined: December 1st, 2006, 9:27 am
Posts: 460
One thing I can think of that is really simple is
Code:
;replace any chars that are not "a-zA-Z0-9_" with underscore
txt := RegExReplace(txt, "\W", "_")
If your text contains only extended chars, you might want another solution, though, because there won't be anything left but underscores!

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 23rd, 2009, 1:53 pm 
Offline

Joined: May 26th, 2009, 6:09 am
Posts: 8
Thanks Micahs.

What about replacing an extended character?

eg. Replace all â with a

txt := RegExReplace(txt, "â", "a")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 23rd, 2009, 2:01 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Code:
txt=âáä
MsgBox % RegExReplace(txt, "â|á|ä", "a") ; or use [âáä]

; Or use a loop
txt=âáäéë
replace=âa|áa|äa|ée|ëe
Loop, Parse, Replace, |
   {
    StringSplit, Part, A_LoopField
    StringReplace, txt, txt, %Part1%, %Part2%, All
   }
MsgBox % txt

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 23rd, 2009, 2:08 pm 
Offline

Joined: May 26th, 2009, 6:09 am
Posts: 8
Thank you both very much.

So I can use the Loop method, then use the "/W" to replace anything i have missed.

So the final code would be

Code:
txt=mïchâël©

;replace ïâë -> iae
replace=ïi|âa|ëe
Loop, Parse, Replace, |
   {
    StringSplit, Part, A_LoopField
    StringReplace, txt, txt, %Part1%, %Part2%, All
   }

;replace any chars that are not "a-zA-Z0-9_" with underscore
txt := RegExReplace(txt, "\W", "_")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 23rd, 2009, 11:50 pm 
Quote:
Not sure what OS you guys are using, but this is the official Microsoft answer:

Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:

* The following reserved characters: < > : " / \ | ? *
* Integer value zero, sometimes referred to as the ASCII NUL character.
* Characters whose integer representations are in the range from 1 through 31, except for streams where these characters are allowed.
* Any other character that the target file system does not allow.

The only obvious conversion into filename problem are the :, / and ? chars that are used in certain titles (have never seen any other of the reserved ones, unless somebody can point them out, actually scratch that, I just remembered movie "Bat*21").

So "Star Wars; Episode III - Revenge of the Sith [2005].mkv", "Æon Flux [2005].mkv" and "Vi på Väddö [1958].avi" are perfect valid filenames. The only reason I sometimes do not use those weird characters is when the auto-approve rate declines from it.

My personal replacement list is as follows:

* : = ;
* / = _
* ? = (nothing, just remove)
* * = ¤ (ALT+0164)
* " = '' (two single quotes)
* < = [ or (
* > = ] or )


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Leef_me, Ohnitiel, XstatyK and 18 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