|
-
Sep 13th, 2005, 08:36 AM
#1
Thread Starter
Hyperactive Member
[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:
StrArray = txtInput.Text.Split(vbCr)
For i = 0 To StrArray.GetUpperBound(0)
StrArray(i).Trim(vbCr)
'I trid StrArray(i).Replace(vbcr,"") also.
'I tried to trim/replace vbcr,vbnewline and vblf
' to see the results
TextBox2.text &= strarray(i)
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:
StrArray = txtInput.Text.Split(vbCr)
For i = 0 To StrArray.GetUpperBound(0)
ListBox1.Items.Add(StrArray(i).Replace(vbLf, ""))
Next
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.
-
Sep 13th, 2005, 09:11 AM
#2
Junior Member
Re: string problem
Check the correction below, You were not assigning the modified(replace) value to anything.
VB Code:
Dim StrArray() As String, i%
StrArray = TextBox1.Text.Split(vbCr.ToCharArray)
For i = 0 To StrArray.GetUpperBound(0)
StrArray(i) = StrArray(i).Replace(vbLf, " ")
' to see the results
TextBox2.Text &= StrArray(i)
Next
J.J.

-
Sep 13th, 2005, 09:37 AM
#3
Re: string problem
If you wanted to use the Split function you would use a different one:
VB Code:
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.
-
Sep 13th, 2005, 02:20 PM
#4
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|