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 part of a string based on a pattern 1

Status
Not open for further replies.

elsenorjose

Technical User
Oct 29, 2003
684
US
CR XI
MySQL 4.1
Windows XP

Ok so I'm sure I've seen the solution to this countless times but I can't remember how to do it.

I have a field that stores URL strings. They are all a little different but share a common format. Couple of examples:

/D/705/19239/v0001/reflector:62123
/D/705/19239/v0001/reflector:62125
/D/705/19239/v0001/reflector:62127

What I want to do is display and group on just the last part of the string after the last '/'. So what I want is:

reflector:62123
reflector:62125
reflector:62127

How would I extract this part of the URL? It's always the last portion of any URL so I would imagine it would be a combination of Right{tbl.fieldname} and InStr but I can't figure it out.

Thanks.
 
Here is one way to do it:

local stringvar array pieces := split({table.field},"/");
pieces[ubound(pieces)]



~Brian
 
Based on your example you can do the following:

Local numbervar w := instr({Field},'reflector:');
local numbervar x := len({Field});

If instr({Field},'reflector:') <> 0 Then Mid({Field},w,x) Else 'not in string'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top