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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting from string 1

Status
Not open for further replies.

GCL2007

IS-IT--Management
Dec 11, 2007
167
US
Hello,
I have a request to extract building code from a string. The problem is they want everything to the left of the last - in the string.
For example, the field could be Bu1-Bu2-Supervisor Shipping or it could just be Bu1-Welder or it can be completely blank.
I guess I want to extract everything before the last - in the field (like Bu1-Bu2 or something like that for the first example.
Any ideas?
Thanks in advance!!!
 
I'm not convinced my solution is the most elegant, but it seems to work using this formula:

[Code {@RESULT}}]
WhilePrintingRecords;
Local NumberVar u := UBound(Split({Table.Column}, '-'));
Local NumberVar i;
Local StringVar R;

If u = 0
Then R := {Table.Column}
Else R := R;

If u = 1
Then R := Split({Table.Column}, '-')[1]
Else R := R;

If u > 1
Then (
For i := 1 to (u-1) step 1 do
R := R + Split({Table.Column}, '-') + '-';
);

If u > 1
Then Left(R, Len(R)-1)
Else R[/Code]

Hope it helps.

Cheers, Pete
 
Thanks Pete - Fantastic job as always.. The only thing I noticed in ym brief check is that if the building code is missing (no -) it is printing the whole string. If there is no - , I'd like it to leave the field blank... Thank you!!!
 
In that case, this should work:

[Code {@RESULT}]
WhilePrintingRecords;
Local NumberVar u := UBound(Split({Table.Column}, '-'));
Local NumberVar i;
Local StringVar R;

If u > 1
Then (
For i := 1 to (u-1) step 1 do
R := R + Split({Table.Column}, '-') + '-';
);

If u > 1
Then Left(R, Len(R)-1)
Else R
[/Code]

Cheers
Pete
 
Thanks again Pete. At first review, looks great.. Now I get to present this to my users... Thanks!!!!
 
Glad I could help. Please post back if you require anything further.

Regards
Pete
 
Actually I am stil having an issue. I have a record where it is Process Eng. PL1 and it is pulling up in the formula as Process Eng . Would like for it to come up blank because of no - . Can you help?
Thanks!!!!
 
Interesting. I just tested that in my test report and the result came up blank as required.

I'm not sure what the problem could be - are you able to upload the report with saved data so I can take a look?

Pete

 
Thanks - My mistake - the field actually read Process Eng. -PL1 I didn't notice the - at first. Your formula properly reported everything to the left of the - It was a data issue.. My apologies and thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top