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

Find string in field 1

Status
Not open for further replies.

Seabz420

IS-IT--Management
Jul 14, 2003
129
CA
Here's the scenerio:
We have a report that includes a field that is about 50 characters long. Within this field is the string ORIG# followed by about 20 characters. The ORIG# isn't always in the same spot, may be at the begining or middle or near the end but is always followed by these 20 characters. I need to be able to go in and retreive 20 characters AFTER the occurance of ORIG#.

I'm thinking what I need to do is somehow count the characters up to the ORIG#, then add 5 to that number. This will give me the number of characters that I need to trim (not the correct term but can't think of anything else), then return 20 characters after that point. I can see what I need to do but just can't get there. Ideas?
 
This should work for you:

Code:
mid({table.field},instr({table.field},{table.orig#}) + length({table.orig#}),20)

This assumes that you know the ORIG#.

~Brian
 
Thanks Brian...I will give this a go but to clarify, the field contains the string "ORIG#" followed by 20 characters. Thanks!
 
You might try:

IF instr("ORIG#",{table.field}) > 0 then
mid({table.field},instr("ORIG#",{table.field})+5)
else
"not found"

-k
 
I've tried the above code (from synapsevampire) and I receive "A string is required here" message when referencing the field name in the instr function.

Here is the exact code:

IF instr("ORIG#",{VW_DTJ.TJD}) > 0 then
mid({VW_DTJ.TJD},instr("ORIG#",{VW_DTJ.TJD})+5)
else
"not found
 
Try:

IF instr({VW_DTJ.TJD},"ORIG#",) > 0 then
mid({VW_DTJ.TJD},instr({VW_DTJ.TJD},"ORIG#")+5, 20)
else
"not found"

-LB
 
Thanks everyone! In the end I used LB's code, which is a combo of everyone's! Great team work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top