wwyngaard Posted September 10, 2002 Posted September 10, 2002 I need to parse out a 5 digit number out of a text string. It can appear anywhere within the text so it can't be a left or right word calc. Is there a way to parse a 5 digit number out? It would seem simple. Also it would be nice to be able to get the 3 letter code following the number. Some example strings. zJobs1 Archive:34939-oul11-2:IT - PDF Folder: zRip2Disk Archive:35727-HOR-2(RSIdata):Default Job:Primex12.eps:Stats: Anchor:55587-afp-02
BobWeaver Posted September 10, 2002 Posted September 10, 2002 Try this: Middle(TheString, Position( Substitute(Substitute(Substitute(Substitute(Substitute( Substitute(Substitute(Substitute(Substitute(Substitute(TheString, "0", "~"), "1", "~"), "2", "~"), "3", "~"), "4", "~"), "5", "~"), "6", "~"), "7", "~"), "8", "~"), "9", "~"), "~~~~~", 1, 1), 5)
wwyngaard Posted September 10, 2002 Author Posted September 10, 2002 Works perfectly. By increasing the last digit I can also get it to grab the 3 letter code and then strip that out by using middle words. If I wanted to just grab the 3 digit code seperately could that be done. I tried reading through the calc to duplicate it to do that and got lost. Thank you Very Much. Wayne
BobWeaver Posted September 11, 2002 Posted September 11, 2002 What this formula does is replace all the numerals with the squiggle "~" character and then search for starting position of five squiggles in a row which is the starting position of the five digit number. To get the 3 character suffix, just add 6 to the position, and change the length to 3 as follows: Middle(TheString, 6+Position( Substitute(Substitute(Substitute(Substitute(Substitute( Substitute(Substitute(Substitute(Substitute(Substitute(TheString, "0", "~"), "1", "~"), "2", "~"), "3", "~"), "4", "~"), "5", "~"), "6", "~"), "7", "~"), "8", "~"), "9", "~"), "~~~~~", 1, 1), 3) Personally, I would just use this to get the whole 9 characters and then process that separately. Considering speed issues, since this is a rather complicated formula, why use it more than once when you can grab the important chunk of 9 characters, and then parse it with much simpler formulas.
wwyngaard Posted September 11, 2002 Author Posted September 11, 2002 That sounds like a good way to go. I wasn't sure if getting all the characters at once then parsing would be faster or not. It makes sense only to run the large parse for 1 calculation. Thanks, Wayne
Recommended Posts
This topic is 8260 days old. Please don't post here. Open a new topic instead.
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