|
-
Oct 17th, 2010, 02:00 AM
#1
Thread Starter
Junior Member
Replacing Multiple vbNewlines
Hi, i'm trying to replace multiple vbnewline's as to only allow two vbnewline's in my textbox. I sort of have a idea how i could do it by counting each instance of vbnewline that appears in my string and then replacing them with only two vbnewline's. But the problem is how could i duplicate the vbnewline sub string using a integer value to match the number of instances found in the string, something simmilar to the string() function.
Last edited by Jackkkkk; Oct 17th, 2010 at 02:18 AM.
-
Oct 17th, 2010, 02:45 AM
#2
Re: Replacing Multiple vbNewlines
I'm struggling to work out what the data in your TextBox might look like, can you give and example of 'before'and 'after' please ?
-
Oct 17th, 2010, 02:46 AM
#3
Re: Replacing Multiple vbNewlines
text1.text = replace(text.text, vblf & vbcr, "")
will remove all empty lines in text box, except if there is empty line at the end
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 17th, 2010, 03:12 AM
#4
Thread Starter
Junior Member
Re: Replacing Multiple vbNewlines
@Doogle The correct formatting of the data would look like this:
Code:
Description:
Description here
more info
more info
even more info
Incorrect would be something like this:
Code:
Description:
Description here
more info
more info
even more info
So basically i need to replace any new lines that are more than 2, with 2 new lines.
Last edited by Jackkkkk; Oct 17th, 2010 at 03:19 AM.
-
Oct 17th, 2010, 08:50 AM
#5
Re: Replacing Multiple vbNewlines
Keep looping until all triple vbNewLines are replaced with two vbNewLines.
vb Code:
Do While InStr(Text1.Text, vbNewLine & vbNewLine & vbNewLine) > 0
Text1.Text = Replace(Text1.Text, vbNewLine & vbNewLine & vbNewLine, vbNewLine & vbNewLine)
Loop
Last edited by Chris001; Oct 17th, 2010 at 09:04 AM.
Reason: typo
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
|