Results 1 to 4 of 4

Thread: [RESOLVED] Split Textbox values

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Resolved [RESOLVED] Split Textbox values

    Hi
    I have an app that reads 2 colums of numbers from a .rtf textfile. The textfile is added to a textbox line by line in a counter. Now I want to split these values to 2 other textboxes. but I don't know how to proceed now. The .rtf textfile is 2 columns of data (imported from Excel), I need this format because it is a pointpair list for Zedgraph. If I use this code both number is added, theres no split:

    Code:
     Dim Str As String = txtTest.Text 
           
            Dim Space_Index As Integer
            Space_Index = Str.IndexOf(" ")
            'This is returning -1 seems theres no space? How can I split the 2 colums?
    
        Dim NewStr As String = Str.Substring(Space_Index + 1, Str.Length - (Space_Index + 1))
     
            Dim NewStr2 As String = Str.Substring(0, Str.Length - (Str.Length - Space_Index))
        
            TextBox1.AppendText(NewStr & ControlChars.NewLine)
            TextBox2.AppendText(NewStr2 & ControlChars.NewLine)
    If the string is ex. "John Doe", the code works.
    The values in the testtextbox looks to have many spaces between them, I guess that it's only the space from the Excel cell. Could need some help here.

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Split Textbox values

    Could be a tab character, maybe the .rtf is tab delimited.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Re: Split Textbox values

    Hi, thank's.
    You where right, it seems like it is Tab delimited.

    Code:
     Dim Space_Index As Integer
            Space_Index = Str.IndexOf(ControlChars.Tab)
            'This is returning 1 which at least say there's a Tab
    But now my the first textbox adds the line without splitting and the second just adds 0.

    Code:
    Dim Space_Index As Integer
            Space_Index = Str.IndexOf(ControlChars.Newline)
            'This is returning 7 this is the last Char.
    The text looks like:
    1 0.00
    2 0.5
    3 15
    4 24
    ...........................

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Re: Split Textbox values

    The code above doesn't work, for some reason. This code do the job correct:

    Code:
    Dim text As String = (line(r))
            Dim DelimitedText() As String, Delimiter As Char = ControlChars.Tab
            DelimitedText = Text.Split(ControlChars.Tab)
            Dim Delimiters() As Char = {ControlChars.Tab}
            For i = 1 To DelimitedText.GetUpperBound(0)
    
            Next
            TextBox1.AppendText(DelimitedText(0) & ControlChars.NewLine)
            TextBox2.AppendText(DelimitedText(1) & ControlChars.NewLine)

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