StrIndex can't find [] characters

Started by rmelcher, October 13, 2015, 10:00:13 AM

Previous topic - Next topic

rmelcher

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;;;

JTaylor

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

td

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

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.)
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

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

td

The simplest 'native' single function call approach is to use the StrScan function. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

Will have to keep that one in mind...don't think I have ever used it.

Jim

rmelcher

Thanks to all, I should have known that.