RobertoFreemano
asked on
Auto close carriage returns/space between paragraghs - VB.NET 2010
HI Experts,
I have a laborious task in work of pasting text into notepad and manually closing-up any extra carriage-returns in the format... I'd like advice on how to paste into a Text Box (win form) and it auto closes spaces...
From: e.g. (currently)
xxxxxx
xxxx
xxxxxxxxx
TO: e.g. (new solution)
xxxxxx
xxxx
xxxxxxxxx
I have a laborious task in work of pasting text into notepad and manually closing-up any extra carriage-returns in the format... I'd like advice on how to paste into a Text Box (win form) and it auto closes spaces...
From: e.g. (currently)
xxxxxx
xxxx
xxxxxxxxx
TO: e.g. (new solution)
xxxxxx
xxxx
xxxxxxxxx
ASKER
Hi CC,
Your code almost works... it leaves 1 space line between cetain text... please see my pic... i've numbered the CR lines.
It is possible to complete close CR?
Thanks,
Roberto
untitled.JPG
Your code almost works... it leaves 1 space line between cetain text... please see my pic... i've numbered the CR lines.
It is possible to complete close CR?
Thanks,
Roberto
untitled.JPG
ASKER
You can try using Trim
Dim txt As String
For each line in textbox1.Lines
If string.IsNullOrEmpty(line) = False Then
txt &= line.trim() & vbcrlf
End If
Next
Textbox1.text = txt.Trim().Trim(vbcrlf).Tr im()
Dim txt As String
For each line in textbox1.Lines
If string.IsNullOrEmpty(line)
txt &= line.trim() & vbcrlf
End If
Next
Textbox1.text = txt.Trim().Trim(vbcrlf).Tr
ASKER
this had no effect - can you check my code - is it something i've done?
Dim txt As String
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
For Each line In TextBox1.Lines
If String.IsNullOrEmpty(line) = False Then
txt &= line.Trim() & vbCrLf
End If
Next
TextBox1.Text = txt.Trim().Trim(vbCrLf).Trim()
End Sub
You are using the wrong event by the way. This will cause an infinite loop. What happens if you use a button or if you use two textboxes?
ASKER
Do you mean <TextBox1_TextChanged> this bit?
Yes
ASKER
I can't see any alternate in Declarations... do you know which one will work please CC?
What I meant was that you are changing the text of textbox in its text_changed event which means the event will fire again, text will be changed again, event will fire again .....
Use one textbox to put text in and another to put modified text in.
Use one textbox to put text in and another to put modified text in.
ASKER
Sorry CC, my brain hurts :(
Do you mean you did not understand me?
ASKER
HI CC,
Sorry Yes! :(
Sorry Yes! :(
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
I think the main difference is I added the trim in below line
If String.IsNullOrEmpty(line. Trim) = False Then
If String.IsNullOrEmpty(line.
ASKER
Sorry CC,
I took an unexpected holiday... back now... will try you code - thanks!
Roberto
I took an unexpected holiday... back now... will try you code - thanks!
Roberto
ASKER
Thanks CC,
Sorry for the slow response.
;)
Sorry for the slow response.
;)
textbox1.text = textbox1.text.replace(vbcr