Showing posts with label characters. Show all posts
Showing posts with label characters. Show all posts

Saturday, March 24, 2012

Text manipulation

Hi

Can someone please help me!? I'm trying to work out how to take text from a multiline asp:TextBox and find and replace the \r\n characters with equivalent HTML <p></p> tags. So that when it is retrieved from the database it can be displayed as correct HTML!

I'm not sure where to start really. I thought that if I did a replace on \r\n\r\n (I think thats what shows a paragraph) with </p><p> that would work. However that wouldn't pick up the beginning of the string, and would add a <p> tag at the end that would fail validation.

Also the reverse is true, if I wanted to put the text back into a textbox for editing, I wouldn't want the HTML to show?!

Please can someone point me in the right direction!

Many thanks

Ross

Hey Dude!

Did you try this:

string.Replace("\r\n","<br/>") ?


kcis8rm:

I'm not sure where to start really. I thought that if I did a replace on \r\n\r\n (I think thats what shows a paragraph) with </p><p> that would work. However that wouldn't pick up the beginning of the string, and would add a <p> tag at the end that would fail validation.

Also the reverse is true, if I wanted to put the text back into a textbox for editing, I wouldn't want the HTML to show?!

You would be better off using one of the free rich text editors. Otherwise \r\r should find a paragraph break, then you would have to manipulate the result of your Replace() operation to add <p> to the beginning, and remove <p> at the end.




Dude

Check this out, I just figured that link for you: http://www.phptr.com/articles/article.asp?p=29585&rl=1

may be it gonna help you to solve your problem, try it out and let me know if it works, else paste your code and we will work on it together.


Hi

Thanks for the help, I think I've now sorted it :-)


I've now sorted this, however you brought up and interesting point! Can you point me in the direction of some of these free rich text editors please?!

kcis8rm:

Hi

Thanks for the help, I think I've now sorted it :-)

Good. What did you do? It might be of interest to others who find this thread.


I solved it by using a regular expression to replace the pattern \r\n\r\n (which shows a paragraph) with the text </p><p> and then adding a <p> to the beginning of the string and a </p> to the end of the string!


Excellent. Any chance of marking my post as the answer then?Wink

Tuesday, March 13, 2012

TextBox - MaxLength property

I have a MultiLine TextBox (WebForm - C#) with the MaxLength property = 1000
but am able to type in an unlimited number of characters. Is there a way to
limit the number of characters that can be typed into this TextBox?only the TextBox.TextMode = "singleLine" or "password" , the
TextBox.MaxLength property is valid
so when you set TextBox.TextMode=MutilLine, the MaxLength property not valid
"mg" <mg@.theworld.com> д?
news:46B9FAB4-A15C-4014-AC26-2A99413A67C6@.microsoft.com...
> I have a MultiLine TextBox (WebForm - C#) with the MaxLength property =
1000 but am able to type in an unlimited number of characters. Is there a
way to limit the number of characters that can be typed into this TextBox?

TextBox - MaxLength property

I have a MultiLine TextBox (WebForm - C#) with the MaxLength property = 1000 but am able to type in an unlimited number of characters. Is there a way to limit the number of characters that can be typed into this TextBox?only the TextBox.TextMode = "singleLine" or "password" , the
TextBox.MaxLength property is valid
so when you set TextBox.TextMode=MutilLine, the MaxLength property not valid

"mg" <mg@.theworld.com> д?
news:46B9FAB4-A15C-4014-AC26-2A99413A67C6@.microsoft.com...
> I have a MultiLine TextBox (WebForm - C#) with the MaxLength property =
1000 but am able to type in an unlimited number of characters. Is there a
way to limit the number of characters that can be typed into this TextBox?

TextBox - MaxLength property

I have a MultiLine TextBox (WebForm - C#) with the MaxLength property = 1000 but am able to type in an unlimited number of characters. Is there a way to limit the number of characters that can be typed into this TextBox?only the TextBox.TextMode = "singleLine" or "password" , the
TextBox.MaxLength property is valid
so when you set TextBox.TextMode=MutilLine, the MaxLength property not valid

"mg" <mg@.theworld.com> д?
news:46B9FAB4-A15C-4014-AC26-2A99413A67C6@.microsoft.com...
> I have a MultiLine TextBox (WebForm - C#) with the MaxLength property =
1000 but am able to type in an unlimited number of characters. Is there a
way to limit the number of characters that can be typed into this TextBox?
only the TextBox.TextMode = "singleLine" or "password" , the
TextBox.MaxLength property is valid
so when you set TextBox.TextMode=MutilLine, the MaxLength property not valid

"mg" <mg@.theworld.com> д?
news:46B9FAB4-A15C-4014-AC26-2A99413A67C6@.microsoft.com...
> I have a MultiLine TextBox (WebForm - C#) with the MaxLength property =
1000 but am able to type in an unlimited number of characters. Is there a
way to limit the number of characters that can be typed into this TextBox?