Link to home
Start Free TrialLog in
Avatar of dplsr
dplsrFlag for Afghanistan

asked on

How do I use the right function and instr to capture all of the characters to the right of a known charachter.

Good morning experts!

I am trying to capture all of the characters to the right of the colon in a string, using the function below, and I am only getting part of the string. I will include all of the pertinent code.

<%# reqoptions(DataBinder.Eval(Container.DataItem, "requiredoption")& string.empty) %>

above returns from the database "Required_Options:Showerhead,Handshower" WITHOUT the function
returns from the database: "erhead,Handshower"  WITH the function      

I think i need to set the length? The length to the right of the colon will vary per record.      

  Protected Function reqoptions(ByVal requiredoption As String) As String
     If requiredoption <> "" Then
     return Right(requiredoption, InStr(requiredoption, ":"))
  else
  return nothing
      End If
 End Function
Avatar of Mikal613
Mikal613
Flag of United States of America image

Protected Function reqoptions(ByVal requiredoption As String) As String
     If requiredoption <> "" Then
     return Right(requiredoption, InStrRev(requiredoption, ":"))
  else
try instrrev
Avatar of dplsr

ASKER

Hi Mikal613,

still returns

erhead,Handshower
right(requiredoption,len(requiredoption) - instrrev(requiredoption,":"))
ASKER CERTIFIED SOLUTION
Avatar of Mikal613
Mikal613
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dplsr

ASKER

Bingo!

thank you!
what is the diference between instr and instrrev (in a nutshell)?
Avatar of willcode4coffee
willcode4coffee

Try this:

Dim iStart As Integer

iStart = RequiredOption.IndexOf(":") + 1
Return RequiredOption.SubStr(iStart, RequiredOption.Length - iStart)

M@
one goes from the right and one goes from the left

basically

Instr goes from the Left

Instr REVERSE goes from the right
The difference between InStr and InstrRev is that InstrRev starts at the END of the string and works backwards while InStr starts at the beginning of the string and works forward.
Avatar of dplsr

ASKER

ok!  have a good day
u 2

Want some cofee?