Cory Posted May 26, 2005 Report Share Posted May 26, 2005 I want to take a path string of a file and break it into several string variables. E.g., from “\\server\share\dir1\dir2\dir3\dir4\last, first 333-22-4444.pdf” I want to get dir2, dir4, last, first and, SSN as separate string variables. (333-22-4444) is the SSN. The number of levels of folders will be consistent and things like the length of the SSN will always be the same but dir1-4 will vary and might have spaces and punctuation. What is the best practice here? I can think of a couple ways to do this and plan on checking out the samples on the website but thought I would ask here first in case some old sage had a quick answer for me. I don’t need a detailed response just a general idea which way to go. Thanks! Quote Link to comment Share on other sites More sharing options...
joe Posted May 26, 2005 Report Share Posted May 26, 2005 I have two answers for this: If you DO NOT have the PGM Functions Library, you can use the Variable Set from Path command to initially parse the string into drive, path, name, extension. And then hack away within a loop to parse the path. If you DO own the PGM Functions Library, you can use the {String - Parse} function to separate the string into different variables by parsing it on the "\" character in a single call. Quote Link to comment Share on other sites More sharing options...
Cory Posted May 26, 2005 Author Report Share Posted May 26, 2005 Thanks. I'm looking at the PGM add in solution but I'm a bit confused by it so far. I opened the manual for it and found it was 308 pages long! I looked at that function but there were som undefined terms in there so I guess I need to look back at some of the preceding 300 pages to see what I missed. Quote Link to comment Share on other sites More sharing options...
randallc Posted May 27, 2005 Report Share Posted May 27, 2005 (edited) Hi, Cory, I'm enthusiastic about the "BasicME" approach ("proof of concept"!), even though it is only for fun and not serious application; I took your case as an example and stimulus to get "InStr$" and "StringSplit$" working; see example macro below (needs v 3.3s) Best, Randall // Parsing a filename Example using "Basic ME" ! -Randall <randallc@ozemail.com.au> Mainly for fun; still lots of bugs, I imagine; not for serious work? (Yo Use the mex file from Forum))Variable Set String %T3% "\\server\share\dir1\dir2\dir3\dir4\last, first 333-22-4444.pdf" // Parse to Env vars as named; Quotes around any commas for Basic Variable Set String %T1% "StringSplit$["%T3%",\,Directories]" Macro Run: {_Basic ME Lite1} // Find last ("characters between rightmost "\" and rightmost ", ") Variable Set String %T1% "BtwCharMid$["%T3%","\",-1,0,", ",-1,0]" Macro Run: {_Basic ME Lite1} Variable Set String %T4% "%AnswerString%" // Find first ("characters between rightmost ", " and rightmost " ") Variable Set String %T1% "BtwCharMid$["%T3%",", ",-1,0," ",-1,0]" Macro Run: {_Basic ME Lite1} Variable Set String %T5% "%AnswerString%" // Find code (assume fixed length) Variable Set String %T1% "RelMid$["%T3%",-15,-5]" Macro Run: {_Basic ME Lite1} Variable Set String %T2% from Environment Variable Text Box Display: StringDisplay2 <REM2:Parsing a filename Example using "Basic ME" ! -Randall <randallc@ozemail.com.au> Mainly for fun; still lots of bugs, I imagine; not for serious work? (Yo Use the mex file from Forum))><TVAR2:03:01:\\server\share\dir1\dir2\dir3\dir4\last, first 333-22-4444.pdf><REM2:Parse to Env vars as named; Quotes around any commas for Basic ><TVAR2:01:01:StringSplit$["%T3%",\,Directories]><MACRUN2:{_Basic ME Lite1}><REM2:Find last ("characters between rightmost "\" and rightmost ", ")><TVAR2:01:01:BtwCharMid$["%T3%","\",-1,0,", ",-1,0]><MACRUN2:{_Basic ME Lite1}><TVAR2:04:01:%AnswerString%><REM2:Find first ("characters between rightmost ", " and rightmost " ")><TVAR2:01:01:BtwCharMid$["%T3%",", ",-1,0," ",-1,0]><MACRUN2:{_Basic ME Lite1}><TVAR2:05:01:%AnswerString%><REM2:Find code (assume fixed length)><TVAR2:01:01:RelMid$["%T3%",-15,-5]><MACRUN2:{_Basic ME Lite1}><TVAR2:02:11:_%Parameter12%_Display><TBOX4:T:1:000239000254000532000391:000:StringDisplay2CODE=%AnswerString% T3=%T3% T4=%T4% T5=%T5% _%Parameter12%_Display= %T2%> CODE=333-22-4444T3=\\server\share\dir1\dir2\dir3\dir4\last, first 333-22-4444.pdf T4=last T5=first _Directories_Display= Environment Variable Answers for StringSplit$ Directories _Directories_0=7 _Directories_1=` _Directories_2=server _Directories_3=share _Directories_4=dir1 _Directories_5=dir2 _Directories_6=dir3 _Directories_7=dir4 _Directories_8=last, first 333-22-4444.pdf EDIT posted 3.4s; fixed for quotes around strings with commas Edited May 30, 2005 by randallc Quote Link to comment Share on other sites More sharing options...
randallc Posted May 28, 2005 Report Share Posted May 28, 2005 (edited) Here it is with PGM Macros; I am not good at these yet! See Floyd's code below; thanks Randall Edited May 29, 2005 by randallc Quote Link to comment Share on other sites More sharing options...
floyd Posted May 28, 2005 Report Share Posted May 28, 2005 Here is a sample using the {String - Parse} function: Variable Set String %T1% "\\server\share\dir1\dir2\dir3\dir4\last, first 333-22-4444.pdf" Variable Set String %T2% "\" Write Registry String: "ParameterString1" Write Registry String: "ParameterString2" Macro Run: { String - Parse } Read Registry Integer: "ReturnInteger1" Activate or Launch: "notepad" OR "notepad.exe" Wait For Window Title: "notepad" Repeat with Variable using %N1% Read Registry String: "Token%N2%" Text Type: Token %N2% = %T1%<ENTER> Repeat End <TVAR2:01:01:\\server\share\dir1\dir2\dir3\dir4\last, first 333-22-4444.pdf><TVAR2:02:01:\><REGWSTR:1:HKEY_CURRENT_USER\Software\Professional Grade Macros\Parameters\ParameterString1><REGWSTR:2:HKEY_CURRENT_USER\Software\Professional Grade Macros\Parameters\ParameterString2><MACRUN2:{ String - Parse }><REGRINT:1:HKEY_CURRENT_USER\Software\Professional Grade Macros\Parameters\ReturnInteger1><REM2:><LAUNCHYES3:0:0112notepad<LAUNCH:notepad.exe><WAITWIN2:000010:000000:notepad><REM2:><REP3:05:000001:000001:0001:1:02:><REGRSTR:1:HKEY_CURRENT_USER\Software\Professional Grade Macros\Parsed Tokens\Token%N2%><TEXTTYPE:Token %N2% = %T1%<ENTER>><ENDREP> All that you need to do is set a Registry value with the string-to-be-parsed and another Registry value to the character (or string) used as the parsing delimiter. Now call the {String - Parse} function, then read the number of parsed strings (tokens) that were generated. Quote Link to comment Share on other sites More sharing options...
Cory Posted June 6, 2005 Author Report Share Posted June 6, 2005 What is "Basic ME"? I broke down and bought the PGM library thingy so I'll mess with that first. Thanks for the example Floyd. Sometimes I just need to see it in motion in order to get it. Quote Link to comment Share on other sites More sharing options...
floyd Posted June 6, 2005 Report Share Posted June 6, 2005 Thanks Cory. Learning by example is the easiest way for me, too. I am not an expert in Randall's BasicME library yet, I have only begun looking at it so I will let him give you an answer. Quote Link to comment Share on other sites More sharing options...
randallc Posted June 6, 2005 Report Share Posted June 6, 2005 OK - Link to site with explanation is in link below in "signatuire" - really just an attempt to look at sting handling easier - see also the "Wizard" which can help with use of PGM too (only one example so far) PGM/MEBasic Wizard Randall Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.