Space in textBox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • *.dpG

    Space in textBox

    Hello
    I have problem with this... In textBox I have some words with space
    between for example
    asdf fhhhh jjjjjkkkkk oooooo
    and space is not same between all word. I try to have only word in
    listBox without space (or in new array) and i try this:
    ----------------------------------------------------------------------------
    Dim stringNeki () As String = textBox.Split(" ")
    For Each stringN As String In stringNeki
    If stringN <" " Then
    lstBox.Items.Ad d(stringN)
    End If
    Next
    but dosen't work....

    Can anybody help me, how to solve this.....

    ThnX....

  • Samuel Shulman

    #2
    Re: Space in textBox

    First replace all double spaces with single spaces like

    s= textbox.text.re place(" ", " ")

    you may have to loop a number of times like

    s=textbox.text

    For i - 0 to 10
    s=s.replace(" ", " ")
    Next

    Then your method will remove the remaining single space

    hth,
    Samuel Shulman

    "*.dpG" <fiksno@yahoo.c omwrote in message
    news:1154383231 .713844.201260@ i3g2000cwc.goog legroups.com...
    Hello
    I have problem with this... In textBox I have some words with space
    between for example
    asdf fhhhh jjjjjkkkkk oooooo
    and space is not same between all word. I try to have only word in
    listBox without space (or in new array) and i try this:
    ----------------------------------------------------------------------------
    Dim stringNeki () As String = textBox.Split(" ")
    For Each stringN As String In stringNeki
    If stringN <" " Then
    lstBox.Items.Ad d(stringN)
    End If
    Next
    but dosen't work....
    >
    Can anybody help me, how to solve this.....
    >
    ThnX....
    >

    Comment

    • Scott M.

      #3
      Re: Space in textBox

      The Split method works on a String, not a Textbox. Also, the .Split(" ")
      will cause all the spaces to be stripped out completely, so you don't want
      to test for <" ", you want to test for <"". The following code works
      for me:

      Dim stringNeki () As String() = textBox.Text.Sp lit(" ")
      For Each stringN As String In stringNeki
      If stringN <"" Then
      lstBox.Items.Ad d(stringN)
      End If
      Next


      "*.dpG" <fiksno@yahoo.c omwrote in message
      news:1154383231 .713844.201260@ i3g2000cwc.goog legroups.com...
      Hello
      I have problem with this... In textBox I have some words with space
      between for example
      asdf fhhhh jjjjjkkkkk oooooo
      and space is not same between all word. I try to have only word in
      listBox without space (or in new array) and i try this:
      ----------------------------------------------------------------------------
      Dim stringNeki () As String = textBox.Split(" ")
      For Each stringN As String In stringNeki
      If stringN <" " Then
      lstBox.Items.Ad d(stringN)
      End If
      Next
      but dosen't work....
      >
      Can anybody help me, how to solve this.....
      >
      ThnX....
      >

      Comment

      • HKSHK

        #4
        Re: Space in textBox

        Hello *.dbG, hello Samuel,

        I would use this approach:

        Dim s As String

        s = TextBox1.Text

        While Instr(s, " ") 0
        s = Replace(s, " ", "")
        End While

        TextBox1.Text = s

        Best Regards,

        HKSHK

        Samuel Shulman wrote:
        First replace all double spaces with single spaces like
        >
        s= textbox.text.re place(" ", " ")
        >
        you may have to loop a number of times like
        >
        s=textbox.text
        >
        For i - 0 to 10
        s=s.replace(" ", " ")
        Next
        >
        Then your method will remove the remaining single space
        >
        hth,
        Samuel Shulman
        >
        "*.dpG" <fiksno@yahoo.c omwrote in message
        news:1154383231 .713844.201260@ i3g2000cwc.goog legroups.com...
        >Hello
        >I have problem with this... In textBox I have some words with space
        >between for example
        >asdf fhhhh jjjjjkkkkk oooooo
        >and space is not same between all word. I try to have only word in
        >listBox without space (or in new array) and i try this:
        >----------------------------------------------------------------------------
        >Dim stringNeki () As String = textBox.Split(" ")
        >For Each stringN As String In stringNeki
        > If stringN <" " Then
        > lstBox.Items.Ad d(stringN)
        > End If
        >Next
        >but dosen't work....
        >>
        >Can anybody help me, how to solve this.....
        >>
        >ThnX....
        >>
        >
        >

        Comment

        • Scott M.

          #5
          Re: Space in textBox

          That doesn't solve the problem that the OP posed. What you've shown will
          simply strip out all the spaces and create 1 resulting string. The OP is
          looking for many text values that were separated by one or more strings.
          This does the trick:

          Dim stringNeki () As String() = textBox.Text.Sp lit(" ")
          For Each stringN As String In stringNeki
          If stringN <"" Then
          lstBox.Items.Ad d(stringN)
          End If
          Next



          "HKSHK" <hkshk@gmx.netw rote in message
          news:44cef9f5$0 $29356$9b622d9e @news.freenet.d e...
          Hello *.dbG, hello Samuel,
          >
          I would use this approach:
          >
          Dim s As String
          >
          s = TextBox1.Text
          >
          While Instr(s, " ") 0
          s = Replace(s, " ", "")
          End While
          >
          TextBox1.Text = s
          >
          Best Regards,
          >
          HKSHK
          >
          Samuel Shulman wrote:
          >First replace all double spaces with single spaces like
          >>
          >s= textbox.text.re place(" ", " ")
          >>
          >you may have to loop a number of times like
          >>
          >s=textbox.te xt
          >>
          >For i - 0 to 10
          >s=s.replace( " ", " ")
          >Next
          >>
          >Then your method will remove the remaining single space
          >>
          >hth,
          >Samuel Shulman
          >>
          >"*.dpG" <fiksno@yahoo.c omwrote in message
          >news:115438323 1.713844.201260 @i3g2000cwc.goo glegroups.com.. .
          >>Hello
          >>I have problem with this... In textBox I have some words with space
          >>between for example
          >>asdf fhhhh jjjjjkkkkk oooooo
          >>and space is not same between all word. I try to have only word in
          >>listBox without space (or in new array) and i try this:
          >>----------------------------------------------------------------------------
          >>Dim stringNeki () As String = textBox.Split(" ")
          >>For Each stringN As String In stringNeki
          >> If stringN <" " Then
          >> lstBox.Items.Ad d(stringN)
          >> End If
          >>Next
          >>but dosen't work....
          >>>
          >>Can anybody help me, how to solve this.....
          >>>
          >>ThnX....
          >>>
          >>

          Comment

          Working...