WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: rmelcher on October 13, 2015, 10:00:13 AM

Title: StrIndex can't find [] characters
Post by: rmelcher on October 13, 2015, 10:00:13 AM
Why can't StrIndex find [] characters?  is there an alternative?, I need to find characters [] in file names.
***********************************************************
*** Debug Initialized ***
==============================
Tue 10/13/2015 12:52:57 PM
WinBatch Studio 2015A
WIL DLL 6.15aoa
\\rarusrafps07.na.jnj.com\HomeH$\xx\Data\WinBatch\DIR Chaser2 SDD Invalid Dir File names.wbt
Windows platform: NT, version: 6.1, build: 7601 (Service Pack 1)
ErrorMode: @CANCEL
Valid Code Signature: Yes
UAC Manifest Settings: level="asInvoker" uiAccess="false"
UAC Elevation Level: Admin Not Elevated
==============================
arg = "[]"
(11482) VALUE STRING => "[]"
loc = StrIndex(arg,'/\[]*:"<>|?',1,@fwdscan)  ; contains any of these
(11482) VALUE INT => 0
exit
(11482) VALUE INT => 0
--- Normal termination ---
;;;END OF JOB;;;
Title: Re: StrIndex can't find [] characters
Post by: JTaylor on October 13, 2015, 10:06:33 AM
I think you may want to read the documentation again, assuming I am understanding what you are doing.

StrIndex() looks for the substring.   As in the entire substring you specify. 

Jim
Title: Re: StrIndex can't find [] characters
Post by: td on October 13, 2015, 10:29:39 AM
StrIndex isn't a regular expression parser.  Its locates the position of a sub-string within a longer text string.  The function is fully documented in the Consolidated WIL Help file which is included in your WinBatch distribution. 

If you wish to use regular expressions in a WIL script, you have serveral choices.  For example, you could use the "VBScript.RegExp" COM Automation object that is a part of the Windows OS.  It has the advantage of simplicity but does not support the full range of regular expression syntax.  To use a more robust implementation of regular expressions you can use the WinBatch CLR hosting subsystem to load the  dotNet "System.Text.RegularExpressions.Regex" class.  The class's documentation can be found here:

https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex%28v=vs.100%29.aspx (https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex%28v=vs.100%29.aspx)

More information about using COM Automation objects and dotNet classes in WinBatch can be found in the Consolidated WIL Help file and on our Tech Database Website (link is on the menu at the top of this page.)
Title: Re: StrIndex can't find [] characters
Post by: JTaylor on October 13, 2015, 10:42:27 AM
If you want to keep it native to WinBatch take a look at StrClean().   You can compare its results to the original and if different you know you have a match.

Jim
Title: Re: StrIndex can't find [] characters
Post by: td on October 13, 2015, 11:15:21 AM
The simplest 'native' single function call approach is to use the StrScan function. 
Title: Re: StrIndex can't find [] characters
Post by: JTaylor on October 13, 2015, 11:34:45 AM
Will have to keep that one in mind...don't think I have ever used it.

Jim
Title: Re: StrIndex can't find [] characters
Post by: rmelcher on October 13, 2015, 11:45:32 AM
Thanks to all, I should have known that.