Forum Moderators: open

Message Too Old, No Replies

recognize line feeds in a multilines text box when filling DB

         

tomatfic

9:42 am on Aug 25, 2005 (gmt 0)

10+ Year Member



Hi
I am filling a database from an asp.net form. This form contains a multiline text box. What I would like to do is replace each carriage return by a slash before sending the data to the database.
That is because I am displaying the data in a csv file and for some reasons if a column contains carriage returns it just messes up the display.
So I am trying to do a replace(textbox,"x"," / ")
Does anyone know what I need to put in place of the x in the above line?
Many thanks, Thomas

mrMister

10:44 am on Aug 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



replace(textbox,vbCr," / ")

Red_Eye

10:47 am on Aug 25, 2005 (gmt 0)

10+ Year Member



The code for carriage return is \n I use string.Replace("\n","<BR>") for format some of the text in my db when sending it to the browser

tomatfic

10:58 am on Aug 25, 2005 (gmt 0)

10+ Year Member



Thanks for your replies, but I found the correct answer for my problem is

Replace(System.Environment.NewLine, " / ")

Thomas

mrMister

11:37 am on Aug 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You asked how to replace a carriage return and my solution does that in the VB / VBScript syntax that you used yourself.

Your solution replaces both a carriage return and line feed together in .Net syntax

Perhaps next time you could explain more learly what you want?

For reference, the contants you might need are as follows

ControlChars.Cr (Carriage Return) (ASCII: 13)
ControlChars.Lf (Line Feed) (ASCII: 10)
ControlChars.NewLine (OS Independant, CR & LF on Windows)

For standard .Net structure, you want to do something like this...

strYourString.Replace(ControlChars.NewLine,"/")
strYourString.Replace(ControlChars.Cr,"/")
strYourString.Replace(ControlChars.Lf,"/")

tomatfic

3:09 pm on Aug 25, 2005 (gmt 0)

10+ Year Member



Ok ill try to make myself clearer next time. I am not an english speaker and did not know there was a difference between carraige return and line feeds ...
I tried your solution (replace(textbox,vbCr," / ")) which did not work, before saying i had found another one

mrMister

4:18 pm on Aug 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code does work. It's VB code. The reason I gave VB code is because you posted VB code! Yes it works on .Net but it's not well structured OOP code.

You need to Import the Microsoft.VisualBasic namespace to get it to work on VB.Net

As I said, you really need to state what language you're using before asking for help ;-)