shornw Posted February 3, 2012 Share Posted February 3, 2012 (edited) Probably easier to read the code first as my attempts to explain it first got too long winded What I would like is for each of the characters : \ / ? * [ ] to be tested in the last Case without writing a separate Case for each. If StringLen($shName) > 30 Then While 1 $shName = InputBox("Tab Name", "Please enter a name for the Excel tab", "", "", 250, 60) If @error = 1 Then Exit Select Case StringLen($shName) > 30 MsgBox(16, "Error", "The name you chose is too long. Names must be 30 characters or less") ContinueLoop Case StringLen($shName) < 1 MsgBox(16, "Error", "You must specify a name for the Excel tab") ContinueLoop Case StringInStr($shName, "\") MsgBox(16, "Error", "Names cannot contain any of the characters listed below" &@CRLF & @CRLF & ': \ / ? * [ ]') ContinueLoop EndSelect ExitLoop WEnd EndIf Can anyone think of a way, or am I just being greedy. Thanks Edited February 3, 2012 by shornw [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
Beege Posted February 3, 2012 Share Posted February 3, 2012 (edited) I think the pattern would be this. Check and see or post an example string to test..$test = StringRegExp($string, '[/?*[]]')edit: nope its this for valid file names..StringRegExp($sList, "[/:<>|]")edit2: seen written by guinness .edit4000: Just look at stringregexp() in the doc. Brackets allow to match any character in the set. e.g. [aeiou] matches any lower-case vowel Edited February 3, 2012 by Beege Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
Robjong Posted February 3, 2012 Share Posted February 3, 2012 Almost, try this one StringRegExp($shName, '[/:*?"<>|]') Link to comment Share on other sites More sharing options...
Beege Posted February 3, 2012 Share Posted February 3, 2012 There you are. I knew you'd show up Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
Robjong Posted February 3, 2012 Share Posted February 3, 2012 haha, was out throwing some snowballs Link to comment Share on other sites More sharing options...
Mikeman27294 Posted February 3, 2012 Share Posted February 3, 2012 Alternatively, try this. It is much simpler, but will do the job perfectly. stringinstr($shName, "") or ($shName, "/") or ($shName, "?") or ($shName, "*") or ($shName, "[") or ($shName, "]") Link to comment Share on other sites More sharing options...
Robjong Posted February 3, 2012 Share Posted February 3, 2012 (edited) If you want it a simple short method and you do not know regular expressions you could (ab)use StringSplit to do it even simpler.Case Not StringSplit($shName, ":/?*[]") And Not @errorEdit: fixed quotesEdit 2: corrected script Edited February 3, 2012 by Robjong Link to comment Share on other sites More sharing options...
Mikeman27294 Posted February 3, 2012 Share Posted February 3, 2012 Hmm... interesting, never thought of that method. Link to comment Share on other sites More sharing options...
shornw Posted February 3, 2012 Author Share Posted February 3, 2012 MikeMan: Haven't tried it but that's the way I would have probably got to eventually, given enough time and patience. Who wasit said 'If you give a room full of monkeys a typewriter each...." Beege & RobJong: I guess the time has come to stop chickening out from using StringRegExp() - Boy, it messes with my head and I've managed to avoid it for years. Time to man up then!!RobJong: Tempting as (ab)using for an easy out may be, I gotta get to grips with regular expressions. They certainly seem to be very powerful. Well, that's my weekend screwed...FYI I elected to use Case StringRegExp($shName, '[\\/:*?"\[\]]') This being the illegal character set for Excel tabs.Yay!! I got the leading backslash to add square brackets right first time. Don't laugh!! Seriously, thank you all for your assistance, very much appreciated [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
Beege Posted February 3, 2012 Share Posted February 3, 2012 Alternatively, try this. It is much simpler, but will do the job perfectly. stringinstr($shName, "\") or ($shName, "/") or ($shName, "?") or ($shName, "*") or ($shName, "[") or ($shName, "]") That would fail, but I think you and the op know that. But even the corrected version kinda ugly. It makes 6 function calls that can easily be done with one. Thats essentially what the op is trying to avoid with all the case statements. If you want it a simple short method and you do not know regular expressions you could (ab)use StringSplit to do it even simpler. Case Not StringSplit($shName, ":\/?*[]") And Not @error Clever! Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
Robjong Posted February 3, 2012 Share Posted February 3, 2012 (edited) Yeah the StringSplit is a bit of a hack but gets the job done and is easy to use for people who want to avoid SRE.If you want to start with regular expressions be sure to check out this website (I recommend you start here with the quickstart), all of it if you can. Learning regex will take you alot longer then a weekend though, trust me There are of course other good resources out there but I suggest you start with that one, it has simple and a bit more advanced examples, but there almost all quite practical and well explained.Good luck and have fun with it.Edit: grammarEdit: link to quickstart Edited February 3, 2012 by Robjong czardas 1 Link to comment Share on other sites More sharing options...
Beege Posted February 3, 2012 Share Posted February 3, 2012 (edited) I also recommend the *** The PCRE (Regular Expression) ToolKit for AutoIT by Geosoft. Makes it very easy for quick expression testing.Nice link Rob Edited February 3, 2012 by Beege Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
Robjong Posted February 3, 2012 Share Posted February 3, 2012 (edited) I was actually looking for that toolkit link, had seen it around but couldn't remember who it was by. Will have to check that out @shornw you almost got the escaping right, you do not need to escape the left bracket [ as its already in a character set. (you will get it later if you don't now) so this will do: StringRegExp($shName, '[/:*?"[]]') btw, if it's for a filename, on Windows these are the disallowed characters I get presented if attempt to rename a file and type one of these characters; / : * ? " [ ] ] Edit: stupid smileys Edited February 3, 2012 by Robjong Link to comment Share on other sites More sharing options...
shornw Posted February 3, 2012 Author Share Posted February 3, 2012 @shornw you almost got the escaping right, you do not need to escape the left bracket [ as its already in a character set. (you will get it later if you don't now) Much, much later I think. BTW, the character set I'm using is the illegal set for use on an Excel workbook tab, not filename (also 32 = max characters for tab) I was giving up my weekend just to preparing to get to grips with SRE. I suspect I will be worm food before I ever got to learn all of it, and I KNOW I'll have lost the will to live before I understand one half [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2012 Moderators Share Posted February 3, 2012 shornw,I found this site very useful when I started with SREs - and I still use it regularly. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Beege Posted February 3, 2012 Share Posted February 3, 2012 (edited) If you want to start with regular expressions be sure to check out this website, all of it if you can. Learning regex will take you alot longer then a weekend though, trust me I found this site very useful when I started with SREs - and I still use it regularly. Is there an echo in here? Edited February 3, 2012 by Beege Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2012 Moderators Share Posted February 3, 2012 Beege, Obviously! But it at least shows that it the site is a good one to start learning about SREs. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now