Results 1 to 4 of 4

Thread: [RESOLVED] string problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Cochin, India
    Posts
    350

    Resolved [RESOLVED] string problem

    In my project, I have a multiline textbox (txtInput) in
    the main form and the user inputs a list of strings. Then I have to copy the input data into an array of strings (StrArray) So I did this:
    VB Code:
    1. StrArray = txtInput.Text.Split(vbCr)
    2. For i = 0 To StrArray.GetUpperBound(0)
    3.     StrArray(i).Trim(vbCr)
    4.     'I trid StrArray(i).Replace(vbcr,"") also.
    5.     'I tried to trim/replace vbcr,vbnewline and vblf
    6.  
    7. ' to see the results
    8. TextBox2.text &= strarray(i)
    9. Next
    But in the textbox2, I saw one special char in each string
    except in the first string. I copied that special char and
    pasted in notepad. That char is something like an 'enter key'
    How can I remove it?

    I tried this also
    VB Code:
    1. StrArray = txtInput.Text.Split(vbCr)
    2. For i = 0 To StrArray.GetUpperBound(0)
    3.     ListBox1.Items.Add(StrArray(i).Replace(vbLf, ""))
    4. Next
    5. ListBox1.Items.CopyTo(StrArray, 0)
    Now it works fine. I want to know whether there is any method
    to do this without using listbox.
    Last edited by jain_mj; Sep 13th, 2005 at 08:40 AM.

  2. #2
    Junior Member J.J. JOHNSTONE's Avatar
    Join Date
    Aug 2002
    Location
    J'ville
    Posts
    19

    Re: string problem

    Check the correction below, You were not assigning the modified(replace) value to anything.


    VB Code:
    1. Dim StrArray() As String, i%
    2.         StrArray = TextBox1.Text.Split(vbCr.ToCharArray)
    3.         For i = 0 To StrArray.GetUpperBound(0)
    4.  
    5.             StrArray(i) = StrArray(i).Replace(vbLf, " ")
    6.  
    7.             ' to see the results
    8.             TextBox2.Text &= StrArray(i)
    9.         Next
    J.J.


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

    Re: string problem

    If you wanted to use the Split function you would use a different one:
    VB Code:
    1. StrArray = System.Text.RegularExpressions.Regex.Split(TextBox1.Text, Environment.NewLine)
    Regex.Split allows you to split on a string instead of just a single character. The good news is that you don't have to use any method because you already have an array of individual lines in the RichTextBox.Lines property.
    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

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Cochin, India
    Posts
    350

    Re: string problem

    I thaught that StrArray(i).Replace(vbLf, " ") will change the original string. thanks for that.
    Thanks jmcilhinney, I am going to use richtextbox.

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