472,983 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 software developers and data experts.

Store Carriage Returns as <br /><br /> or <p></p>

I have a multi line text in an admin page on my cms.

I am trying to capture carriage returns as and replace them with
<p></p> bfore the string gets written to the database.

I have tried all the charcontrols option and chr(13) with success.. was
using the following code:

Dim s As String = MyTextbox.Text

s = "<p>" & s & "</p>"
s.Replace(ControlChars.CrLf & ControlChars.CrLf, "</p><p>")
s.Replace(ControlChars.Lf, "<br />")
s.Replace("\n", "<br />")
s.Replace(ControlChars.Cr & ControlChars.Cr, "</p><p>")
s.Replace(ControlChars.NewLine, "<br />")
s.Replace(ControlChars.VerticalTab, "<br />")
s.Replace(Chr(13), "<br />")

I have tried all the above, but non have worked.

The only work around i have found is to perform a string.replace when
displaying on the webpage by the following:

<%# container.dataitem("MyTextField").replace(chr(13), "<br />") %>

This works but is not ideal as it means i have to hard code each page.

How do i do this?

Nov 19 '05 #1
2 2484
If you look at the documentation for String.Replace()
[http://msdn.microsoft.com/library/de...acetopic2.asp]
you'll see that it the return value of the method is "A string equivalent to
this instance but with all instances of oldValue replaced with newValue."
In other words, the method does not change the original string, it returns
the string with the replacements. When you use it with your databinding
code, the runtime is rendering the output of the replace method.

You'll need to store the results of the method somewhere if you intend to
use them (write them to a database):
s = s.Replace(...)
or
s = MyTextbox.Text.Replace(...)

HTH
----------------
Dave Fancher
http://www.davefancher.com

"Winshent" <wi*************@yahoo.co.uk> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I have a multi line text in an admin page on my cms.

I am trying to capture carriage returns as and replace them with
<p></p> bfore the string gets written to the database.

I have tried all the charcontrols option and chr(13) with success.. was
using the following code:

Dim s As String = MyTextbox.Text

s = "<p>" & s & "</p>"
s.Replace(ControlChars.CrLf & ControlChars.CrLf, "</p><p>")
s.Replace(ControlChars.Lf, "<br />")
s.Replace("\n", "<br />")
s.Replace(ControlChars.Cr & ControlChars.Cr, "</p><p>")
s.Replace(ControlChars.NewLine, "<br />")
s.Replace(ControlChars.VerticalTab, "<br />")
s.Replace(Chr(13), "<br />")

I have tried all the above, but non have worked.

The only work around i have found is to perform a string.replace when
displaying on the webpage by the following:

<%# container.dataitem("MyTextField").replace(chr(13), "<br />") %>

This works but is not ideal as it means i have to hard code each page.

How do i do this?

Nov 19 '05 #2
acknowledged..

i was having one of those days !!

thanks.

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: fis | last post by:
Hi all, I've problem because there are needed break lines in my texts on the web site but i can't do it :( My pipeline looks like: XMS -> I18N -> XSLT -> HTML I have lot of texts in my...
6
by: Lasse | last post by:
I have done this simple function, it seems to work as intended, to solve a problem i have had for a while. I couldnt find any sample around that was working for me. I would like to test it with...
12
by: thomas_jedenfelt_1 | last post by:
Hi everyone, Is the W3C HTML Validator in error when it returns <br /> as valid for HTML 4.01 Strict doctype? In March 2004 , the Validator returned <br />, <hr /> and <img /> as invalid for...
7
by: noor.rahman | last post by:
I have an XML file that stores data from an HTML form. I use XSL to display the data in HTML format. The data may have newline characters. However, XSL is not displaying the newlines properly in...
1
by: Winshent | last post by:
I have a multi line text in an admin page on my cms. I am trying to capture carriage returns as and replace them with <p></p> bfore the string gets written to the database. I have tried all...
13
by: CK | last post by:
Hi all, I have a textarea control. I am putting it's value in an html email. The problem is that the new lines are being ignored. I want to take the controls value and replace any newline...
9
by: Wayne | last post by:
$a = $_POST; # txt_content = This is a<CR><LF>Test $p = str_replace ("%0D%0A", "<br>", $a); That is the above code that I am using, however, it is not picking up the CR/LF from the textarea. I...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.