Parsing a Line Sample

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Parsing a Line Sample

Post by Bob Hansen » Mon Oct 20, 2003 7:12 pm

A different posting http://www.mjtnet.com/usergroup/viewtop ... =2663#2663 asked about a sample of "parsing a line" I am submitting this as an example using the line from the earlier posting as the example line. Here is the original line to be parsed. Need to get the height and width values.
JPEG image 1168x1022 pixels has the following structure:
//Sample code for parsing a string
//Bob Hansen, Sensible Solutions Inc.
//Created 10/20/03

//Brief explanation of what needs to be done:
//Basic tools to parse string are MidStr> and Position>
//Syntax of: MidStr>string,start,length,result
//So we need to determine the starting positions and the lengths of strings that we want.
//Position> can be used to find the starting position of a desired value(string)
//Syntax of: Position>substring,string,start,result
//================================================
Label>Start
//Save the string with the information, copied to the clipboard, in a variable (Info)
//GetClipboard>Info
//For test purposes we will force a value by using Let> instead.
//For test purposes, change the values from 1168x1022 to other values of varying lengths
Let>Info=JPEG image 1168x1022 pixels has the following structure:


Label>Divider
//Get position of "x" in the string
Position>x,%Info%,1,divider


Label>HeightValue
//Get position of "image " in the string before the height value
Position>image,%Info%,1,First

//Determine beginning of height value position by adding lenth of "image " (Note the trailing space character)
Add>First,6

//Determine length of height value
Let>Length=%divider%-%First%

//Extract the value of height and save it
MidStr>%Info%,%First%,%Length%,Height


Label>WidthValue
//Get position of " pixels" in the string after the width value (Note the leading space character).
Position> pixels,%Info%,1,Last

//Determine beginning of width value position by adding 1 to the divider
Add>divider,1

//Determine length of width value
Let>Length=%Last%-%divider%

//Extract the value of width and save it
MidStr>%Info%,%divider%,%Length%,Width


Label>End
MessageModal>Height of image is %Height%%CRLF%%CRLF%Width of image is %Width%
If you cut and paste this code, be sure to remove any trailing spaces at end of lines.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts