Allowing only certain characters?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Allowing only certain characters?

Post by Phil Pendlebury » Fri Feb 16, 2007 8:14 pm

Once again I have searched and found some close but not close enough for my limited understanding.

I have a section in my script that enters the result of a variable into a file save dialog.

However, as you know, Windows hates certain characters in file names. So I am trying to strip them from the variable.

To be more specific; I need to read variable %filname% and replace anything that isn't "A-Z, a-z, 1-0, with probably an underscore or even a space. (I don't need to worry about the file extension)

So: my$file.name would become my_file_name

Can anyone point me in the right direction? I can do it by replace but there are so many characters to replace... I hoped that there may be an "allow only" feature.

Thanks.

:)
Phil Pendlebury - Linktree

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Feb 16, 2007 8:54 pm

Quick point in one direction, untested. I think it is the right direction. .....

Check out using Regular Expressions with the VBScript. You could pass the file name to the RegEx function and have it return the cleaned up version of what you want.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Fri Feb 16, 2007 9:00 pm

Thanks Bob, I haven't a clue about VB script.

Still I can use Google like anyone else I guess...

:-)
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Sat Feb 17, 2007 12:19 am

Well this will have to do for me I guess. Not the most elegant solution but it will do:

Code: Select all

// ENTER DISALLOWED CHARACTERS 
Let>notallowed=ENTER CHARS HERE FOR SOME REASON THIS FORUM WON'T ALLOW THEM TO BE ENTERED - COMMAS BRACKETS ETC.

Length>%notallowed%,naloop

// INPUT SOMETHING
Input>blah,DO IT!,Put some stuff here

// CHECK TO SEE IF DISALLOWED CHARS ARE IN INPUT 
Let>rep=1
Repeat>rep
MidStr>%notallowed%,rep,1,isitthere
// FIND DISALLOWED AND IF ITS THERE REPLACE IT WITH UNDERSCORE
StringReplace>%blah%,isitthere,_,blah

Let>rep=rep+1
Until>rep>naloop

// SHOW RESULT
MsgModal>%blah%
Wait>10
Phil Pendlebury - Linktree

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts