3170_de-DE
Obtaining substrings with variable number of charactersI have a set of file names that contain within the name an ID number. These ID numbers do not necessarily have the same character length. Any ideas on how to achieve this? This is what I have for fixed ID character length.
For (k =1,
k < N Items( listOfFiles ),
k++,
IDNumber = subsr( listOfFiles, 1, 8 );
insertinto( listOfIDNumbers, IDNumber );
);
Issue arises when ID number is not 7 characters in length and I have complex filenames.
ABCDE_1234567_ABCD.csv
ABC_123_ABCDEFG.csv
What I want is to just get 1234567 and 123. Can I key off .csv somehow or perhaps underscore?Re: Obtaining substrings with variable number of charactersGood point about regular expressions. For the record, in the case you described, the following would also work:
IDNumber = Word( 1, listOfFiles, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" )Re: Obtaining substrings with variable number of charactersThe other option would be to leverage regular expressions. If the file names did not have _'s separating the various portions but the ID name was uniquely composed of numbers and the rest of the file name did not contain numbers then this would work.
A regex syntax guide that I always reference is:
http://www.regular-expressions.info/reference.html
Fixed a stupid grammar mistake
Message was edited by: mewingRe: Obtaining substrings with variable number of charactersThat works great, thanks for the help!Re: Obtaining substrings with variable number of charactersTry this:
IDNumber = Word( 1, listOfFiles, "_" )
Comments
There are no comments yet