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

Parsing a string to get a value to the right of another value

Status
Not open for further replies.

cgherman

Programmer
Jun 23, 2010
4
0
0
US
I have many random values like these and I need a way to grab the part that is to the right of "-->".

Geo --> IPD-Embedded IA

Segment --> MAG

I'm using this code to grab the part that is to the left, but I cannot figure out how to alter it to get the value to the right.

LPos = InStr(My_Value, "-->")

rst![Chart_Field] = Trim(Left(My_Value, LPos - 1))

Can someone help?

Thanks!
 
= Trim(Mid(My_Value, LPos + 2))

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

You have to accommodate the length of [tt]' --> '[/tt] which is 5:
Code:
= Trim(Mid(My_Value, LPos + [blue]5[/blue]))

Have fun.

---- Andy
 
or
=trim(split(myvalue,"-->")(1))
or to get the first half
=trim(split(myvalue,"-->")(0))
 
Thanks a lot for your responses, but unfortunately, they are not working. Here are a few examples of what is happening, which is the same for each suggestion given to me. Maybe I didn't give enough info, so I hope this clarifies.

Using my value of "Segment --> Energy", I get "ergy"

Using my value of "TTL --> IPD-Embedded IA", I get nothing

Using my value of "CostCent --> 855GME", I get "55GME"

As you can see, the length of my string can very so the position of "-->" can very within the string too. I want to grab everything to the right of "-->". The trim will remove any extra spaces.

Thanks again!
Clint
 
That is why I posted the alternate version. It is length idependent.
 
MajP, you are ABSOLUTELY right! Your code works fine when I plug it into the RIGHT PLACE. :)

Sorry about that and thanks!
 

I would go with MajP's sollution, but to prove that my code will work OK, here is the code:
Code:
Dim My_Value As String
Dim LPos As Integer

My_Value = "Segment  -->  Energy"
LPos = InStr(My_Value, "-->")

Debug.Print Trim(Mid(My_Value, LPos + 5))
[green]'Energy   [/green]

My_Value = "TTL  -->  IPD-Embedded IA"
LPos = InStr(My_Value, "-->")

Debug.Print Trim(Mid(My_Value, LPos + 5))
[green]'IPD-Embedded IA   [/green]

My_Value = "CostCent  -->  855GME"
LPos = InStr(My_Value, "-->")

Debug.Print Trim(Mid(My_Value, LPos + 5))
[green]'855GME   [/green]
You HAVE to re-calculate [tt]LPos[/tt] for every [tt]My_Value[/tt]

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top