dplsr
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:Showerhe ad,Handsho wer" 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
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
above returns from the database "Required_Options:Showerhe
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
try instrrev
ASKER
Hi Mikal613,
still returns
erhead,Handshower
still returns
erhead,Handshower
right(requiredoption,len(r equiredopt ion) - instrrev(requiredoption,": "))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bingo!
thank you!
what is the diference between instr and instrrev (in a nutshell)?
thank you!
what is the diference between instr and instrrev (in a nutshell)?
Try this:
Dim iStart As Integer
iStart = RequiredOption.IndexOf(":" ) + 1
Return RequiredOption.SubStr(iSta rt, RequiredOption.Length - iStart)
M@
Dim iStart As Integer
iStart = RequiredOption.IndexOf(":"
Return RequiredOption.SubStr(iSta
M@
one goes from the right and one goes from the left
basically
Instr goes from the Left
Instr REVERSE goes from the right
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.
ASKER
ok! have a good day
u 2
Want some cofee?
Want some cofee?
If requiredoption <> "" Then
return Right(requiredoption, InStrRev(requiredoption, ":"))
else