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

instr find left of character 2

Status
Not open for further replies.

GROKING

Programmer
Joined
Mar 8, 2005
Messages
26
Location
US

ok,
I have a file I am reading in and need to convert the string by keeping data to the left of the character without the space.

here is the campaignValue string = "house - content"

Dim newcamp As String
Dim newcamp1 As Integer

newcamp1 = InStr(campaignValue, "-")
If newcamp1 > 0 Then
newcamp = InStr(campaignValue, newcamp1)
Else
newcamp = campaignValue
End If

this returns the right "- content" but I need the left "house"

any ideas?? helping others is rewarding!!
 
Here is an example:
Code:
        Dim s As String = "house - content"
        Dim i As Integer
        i = s.IndexOf("-") - 1

        If i > 0 Then
            Response.Write(Left(s, i))
        End If

Jim
 
Sorry I just realized I displayed the result for a web app, you can use messagebox.show()

 
I get this error message:
Error 1 'Public Property Left() As Integer' has no parameters and its return type cannot be indexed.

Dim s As String = campaignValue
Dim i As Integer
Dim newcamp as String

i = s.IndexOf("-") - 1

If i > 0 Then
newcamp = Left(s, i)
End If
 
Yeah sorry about that, Left works in a web app not in VB.NET
Try this:
Code:
       Dim s As String = "house - content"
        Dim i As Integer
        i = s.IndexOf("-") - 1

        If i > 0 Then
            MessageBox.Show(s.Substring(0, i))
        End If
[/code)
 
Code:
Dim s As String = "house - content"
s = s.split("-")(0).trim
response.write s

That should return the first piece of the string before the "-" with the white space removed.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks Rick, you da man
 
That's cool it works, but I am confused by the syntax. Care to explain the (0) after the split?

Thanks...

Jim
 
Very cool, thanks for the explination, makes sense now!

Jim

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top