[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-11-17
11
Medium Priority
?
246 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:dplsr
  • 6
  • 3
  • 2
11 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 12605383
Protected Function reqoptions(ByVal requiredoption As String) As String
     If requiredoption <> "" Then
     return Right(requiredoption, InStrRev(requiredoption, ":"))
  else
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12605389
try instrrev
0
 

Author Comment

by:dplsr
ID: 12605478
Hi Mikal613,

still returns

erhead,Handshower
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:Mikal613
ID: 12605547
right(requiredoption,len(requiredoption) - instrrev(requiredoption,":"))
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 2000 total points
ID: 12605552
Protected Function reqoptions(ByVal requiredoption As String) As String
     If requiredoption <> "" Then
     return right(requiredoption,len(requiredoption) - instrrev(requiredoption,":"))
  else
  return nothing
      End If
 End Function
0
 

Author Comment

by:dplsr
ID: 12605598
Bingo!

thank you!
what is the diference between instr and instrrev (in a nutshell)?
0
 
LVL 4

Expert Comment

by:willcode4coffee
ID: 12605644
Try this:

Dim iStart As Integer

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

M@
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12605648
one goes from the right and one goes from the left

basically

Instr goes from the Left

Instr REVERSE goes from the right
0
 
LVL 4

Expert Comment

by:willcode4coffee
ID: 12605655
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.
0
 

Author Comment

by:dplsr
ID: 12605683
ok!  have a good day
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12605727
u 2

Want some cofee?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question