Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting numerical data between two delimiters with conditions 2

Status
Not open for further replies.

Hellsteeth

Systems Engineer
May 8, 2018
2
NL
Hello, I am usually pretty good with Crystal Reports but this one has got me stumped so reaching out for any guidance. I am using Crystal Reports 2011.
I have data that is in one of the following three formats held in a string field.
1. ABC-1 @ 123E
2. ABC-1 @ 123W
3. Other data not containing the @ symbol for example “Future Planning”
The characters represented by ABC will always be standard letters of the alphabet A to Z in capitals and three characters long.
The numbers 123 will always be numbers 0 to 9 but may contain a decimal place. Examples would be “5.0”, “7.23”, “35”, "105".
The hyphen, blank spaces and @ are always consistent with respect to formatting as shown in options 1 and 2 above.
The last letter in option 1 and 2 can only ever be an E or W representing angles East or West.
What I would like to do is extract just the number as follows;
In the event the last letter is E, then just extract the numbers 123.
In the event the last letter is W, then extract the number but convert it to an Easterly angle 237 (360-123 = 237).
In the event the data is not in this format, consistently output the number 0.
Some examples;
Data = “DEF-5 @ 26.8E” then output 26.8 as a number.
Data = “FGH-9 @ 105W” then output 255 as a number. (The result of subtracting 105 from 360)
Data = “Some other text” then output 0 as a number

Hopefully this is a clear explanation but will respond to any questions for further clarifications.
Thank you for looking.
 
stringvar x := {table.string};
stringvar array y := split(x," ");
numbervar j := ubound(y);
numbervar z := 0;

if right(y[j],1)="E" then
z := tonumber(left(y[j],len(y[j])-1)) else
if right(y[j],1)="W" then
z := 360-tonumber(left(y[j],len(y[j])-1)) else
if not("@" in x) then
z := 0;
z

-LB
 
Just realized that if E or W could end an instance that does not contain a "@" you should add a clause like this:

stringvar x := {table.string};
stringvar array y := split(x," ");
numbervar j := ubound(y);
numbervar z := 0;

if "@" in x and
right(y[j],1)="E" then
z := tonumber(left(y[j],len(y[j])-1)) else
if "@" in x and
right(y[j],1)="W" then
z := 360-tonumber(left(y[j],len(y[j])-1)) else
if not("@" in x) then
z := 0;
z

-LB
 
Wow!
Thank you lbass, that works a treat, first time.
Good catch on your second post also - in case the text entry ends in an E or W as well. I did not think of that scenario which is of course completely possible.
Very much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top