Results 1 to 5 of 5

Thread: [RESOLVED] Delete string split symbol

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Resolved [RESOLVED] Delete string split symbol

    Hello,

    I have the following string in Cooridnates:

    (0,0,11,11)#(1,1,22,334)#(34,54,55,66)

    With the following code I delete the last coordinates:

    VB Code:
    1. strCoordinates = Coordinates.Split("#")
    2.             strCoordinates(counter) = ""
    3.             Coordinates = Join(strCoordinates, "#")
    4.             TextBox1.Text = Coordinates

    The coordinates now look like this:

    (0,0,11,11)#(1,1,22,334)#

    However they should look like this:

    (0,0,11,11)#(1,1,22,334)

    How do I get rid of the LAST "#"???

    Thanks in advance guys

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Delete string split symbol

    Don't use Split at all.
    VB Code:
    1. Dim myString As String = "(0,0,11,11)#(1,1,22,334)#(34,54,55,66)"
    2.  
    3. myString = myString.Substring(0, myString.LastIndexOf("#"c))
    Note that if the string doesn't contain that character that code will throw an exception, so if you aren't already sure then you need to test it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Re: Delete string split symbol

    Thank you very very much,

    That works perfect.

    But now were still on the subject of strings .

    Like you said I have to check for the "#" value in my string or otherwise I get an error message.

    I tried the following:

    VB Code:
    1. If Coordinates Like "*#*" Then
    2.   Coordinates = Coordinates.Substring(0, Coordinates.LastIndexOf("#"c))
    3. Else
    4.   Coordinates = ""
    5. End If


    But I still get the error message...

  4. #4
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: Delete string split symbol

    VB Code:
    1. Dim myString As String = "Hello#"
    2.         If myString.Contains("#") Then
    3.             'Do stuff
    4.         End If
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Re: Delete string split symbol

    Thank you very very much for all your help guys...

    Everything works perfect...

    CU Next time...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width