|
-
April 11th, 2008, 10:34 PM
#1
shorten it up
I have a document but there are many carriage returns in each paragraph
I'd like to delete some of them for the paragraph to be shorter
For example if there are N carriage returns then I'd like to delete N-1 starting from the second \n
Any help is appriciated.
-
April 11th, 2008, 11:41 PM
#2
Re: shorten it up
Use .Replace() to change all 3 <ret>'s into 2 for ALL occurences
Then you will have all single space, except when there were more than 3
Then, do the same thing to replace a 2 <ret>'s into 1 for single spaced
-
April 12th, 2008, 10:57 AM
#3
Re: shorten it up
I used a regular expression to find all occurences of 3 or more consecutive returns and replace it with only two returns.
Code:
//I'm pulling the start text out of a textbox.
string startText = textBox1.Text;
//This regular expression matches 3 or more line returns.
Regex MultipleLineReturns = new Regex(@"(\r\n){3,}");
//Replace all occurrences of 3 or more line returns with 2 line returns.
//And wing it back in the text box.
textBox1.Text = MultipleLineReturns.Replace(startText, "\r\n\r\n");
That will turn this:
Code:
One return
Two Returns
Three Returns
Four Returns
End
Into this:
Code:
One return
Two Returns
Three Returns
Four Returns
End
Hope that helps.
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
|