By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,110 Members | 1,629 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,110 IT Pros & Developers. It's quick & easy.

C# equiv of Chr(13)

P: n/a
Lo,

In a previous version of an app, I used replace to convert multiline text
boxes to something easier to put in a database, and then i used
replace(chr(13), "<br>") when i needed to show the data.

I'm now working on a new version of this app, and im using C# / .NET.
Obviously I'm using the old database, but I cant find out how to do
replace(chr(13), "<br>").

Basically, what's Chr(13) in C# :o)

Cheers
Dan
Nov 18 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Dan,

I think you are looking for "\n".

-Chris
http://weblogs.austinspad.com/caustin

"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:F3**********************************@microsof t.com...
Lo,

In a previous version of an app, I used replace to convert multiline text
boxes to something easier to put in a database, and then i used
replace(chr(13), "<br>") when i needed to show the data.

I'm now working on a new version of this app, and im using C# / .NET.
Obviously I'm using the old database, but I cant find out how to do
replace(chr(13), "<br>").

Basically, what's Chr(13) in C# :o)

Cheers
Dan

Nov 18 '05 #2

P: n/a
Try System.Environment.NewLine

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:F3**********************************@microsof t.com...
Lo,

In a previous version of an app, I used replace to convert multiline text
boxes to something easier to put in a database, and then i used
replace(chr(13), "<br>") when i needed to show the data.

I'm now working on a new version of this app, and im using C# / .NET.
Obviously I'm using the old database, but I cant find out how to do
replace(chr(13), "<br>").

Basically, what's Chr(13) in C# :o)

Cheers
Dan

Nov 18 '05 #3

P: n/a
Hi guys

Neither of those work. I think I need to actually put the ascii char 13, but
im not sure how to do it. In the db it looks like a little square box! It's
that I want to replace with <br>.

Any ideas?
"Chris Austin" wrote:
Dan,

I think you are looking for "\n".

-Chris
http://weblogs.austinspad.com/caustin

"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:F3**********************************@microsof t.com...
Lo,

In a previous version of an app, I used replace to convert multiline text
boxes to something easier to put in a database, and then i used
replace(chr(13), "<br>") when i needed to show the data.

I'm now working on a new version of this app, and im using C# / .NET.
Obviously I'm using the old database, but I cant find out how to do
replace(chr(13), "<br>").

Basically, what's Chr(13) in C# :o)

Cheers
Dan


Nov 18 '05 #4

P: n/a
Have you tried using RegularExpressions yet? Perhaps doing something like
the following will help:
String myNewTest = Regex.Replace(test, @"\n", "<br>",
RegexOptions.Multiline);

You will have to import the System.Text.RegularExpressions library.

Here is a list of the different characters escapes
http://msdn.microsoft.com/library/de...terescapes.asp

HTH

-Chris
~
http://weblogs.austinspad.com/caustin

"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:38**********************************@microsof t.com...
Hi guys

Neither of those work. I think I need to actually put the ascii char 13, but im not sure how to do it. In the db it looks like a little square box! It's that I want to replace with <br>.

Any ideas?
"Chris Austin" wrote:
Dan,

I think you are looking for "\n".

-Chris
http://weblogs.austinspad.com/caustin

"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:F3**********************************@microsof t.com...
Lo,

In a previous version of an app, I used replace to convert multiline text boxes to something easier to put in a database, and then i used
replace(chr(13), "<br>") when i needed to show the data.

I'm now working on a new version of this app, and im using C# / .NET.
Obviously I'm using the old database, but I cant find out how to do
replace(chr(13), "<br>").

Basically, what's Chr(13) in C# :o)

Cheers
Dan


Nov 18 '05 #5

P: n/a
Hi Chris,

Just tried that, same result: it does nothing. I'm lost!

Dan
"Chris Austin" wrote:
Have you tried using RegularExpressions yet? Perhaps doing something like
the following will help:
String myNewTest = Regex.Replace(test, @"\n", "<br>",
RegexOptions.Multiline);

You will have to import the System.Text.RegularExpressions library.

Here is a list of the different characters escapes
http://msdn.microsoft.com/library/de...terescapes.asp

HTH

-Chris
~
http://weblogs.austinspad.com/caustin

"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:38**********************************@microsof t.com...
Hi guys

Neither of those work. I think I need to actually put the ascii char 13,

but
im not sure how to do it. In the db it looks like a little square box!

It's
that I want to replace with <br>.

Any ideas?
"Chris Austin" wrote:
Dan,

I think you are looking for "\n".

-Chris
http://weblogs.austinspad.com/caustin

"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:F3**********************************@microsof t.com...
> Lo,
>
> In a previous version of an app, I used replace to convert multiline text > boxes to something easier to put in a database, and then i used
> replace(chr(13), "<br>") when i needed to show the data.
>
> I'm now working on a new version of this app, and im using C# / .NET.
> Obviously I'm using the old database, but I cant find out how to do
> replace(chr(13), "<br>").
>
> Basically, what's Chr(13) in C# :o)
>
> Cheers
>
>
> Dan


Nov 18 '05 #6

P: n/a
in c#

"\r" = chr(13)
"\n" = chr(10)
mystring.Replace("\r","<br>");

-- bruce (sqlwork.com)
"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:F3**********************************@microsof t.com...
Lo,

In a previous version of an app, I used replace to convert multiline text
boxes to something easier to put in a database, and then i used
replace(chr(13), "<br>") when i needed to show the data.

I'm now working on a new version of this app, and im using C# / .NET.
Obviously I'm using the old database, but I cant find out how to do
replace(chr(13), "<br>").

Basically, what's Chr(13) in C# :o)

Cheers
Dan

Nov 18 '05 #7

P: n/a
This worked for me. Difference is it needed to use "\r" instead of "\n".

static void Main(string[] args)
{
FileStream fs = File.OpenRead("Data.txt");
StreamReader reader = new StreamReader(fs);
string myInput = reader.ReadToEnd();
reader.Close();
fs.Close();
string myOutput = Regex.Replace(myInput, @"\r", "<br>",
RegexOptions.Multiline);

Console.WriteLine(myOutput);
}

Data.Text contained:

This is a test for new lines.
This is a test for new lines.
This is a test for new lines.
This is a test for new lines.
This is a test for new lines.
This is a test for new lines.
This is a test for new lines.
This is a test for new lines.
This is a test for new lines.

HTH

-Chris
~
http://weblogs.austinspad.com/caustin

"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:FB**********************************@microsof t.com...
Hi Chris,

Just tried that, same result: it does nothing. I'm lost!

Dan
"Chris Austin" wrote:
Have you tried using RegularExpressions yet? Perhaps doing something like the following will help:
String myNewTest = Regex.Replace(test, @"\n", "<br>",
RegexOptions.Multiline);

You will have to import the System.Text.RegularExpressions library.

Here is a list of the different characters escapes
http://msdn.microsoft.com/library/de...terescapes.asp
HTH

-Chris
~
http://weblogs.austinspad.com/caustin

"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:38**********************************@microsof t.com...
Hi guys

Neither of those work. I think I need to actually put the ascii char 13,
but
im not sure how to do it. In the db it looks like a little square box!

It's
that I want to replace with <br>.

Any ideas?
"Chris Austin" wrote:

> Dan,
>
> I think you are looking for "\n".
>
> -Chris
> http://weblogs.austinspad.com/caustin
>
> "Dan Nash" <da*@musoswire.co.uk> wrote in message
> news:F3**********************************@microsof t.com...
> > Lo,
> >
> > In a previous version of an app, I used replace to convert
multiline text
> > boxes to something easier to put in a database, and then i used
> > replace(chr(13), "<br>") when i needed to show the data.
> >
> > I'm now working on a new version of this app, and im using C# /

..NET. > > Obviously I'm using the old database, but I cant find out how to do > > replace(chr(13), "<br>").
> >
> > Basically, what's Chr(13) in C# :o)
> >
> > Cheers
> >
> >
> > Dan
>
>
>


Nov 18 '05 #8

P: n/a
Hi Dan,

Try this :
Byte[] myBytes13 = {13};

string myStr13 = System.Text.Encoding.ASCII.GetString(myBytes13);

dbString.Replace(myStr13, "<br>")

Sorry, I did not have time to test to see if this actually works.

Tod Birdsall, MCP
http://tod1d.blogspot.com

"Dan Nash" <da*@musoswire.co.uk> wrote in message news:<38**********************************@microso ft.com>...
Hi guys

Neither of those work. I think I need to actually put the ascii char 13, but
im not sure how to do it. In the db it looks like a little square box! It's
that I want to replace with <br>.

Any ideas?
"Chris Austin" wrote:
Dan,

I think you are looking for "\n".

-Chris
http://weblogs.austinspad.com/caustin

"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:F3**********************************@microsof t.com...
Lo,

In a previous version of an app, I used replace to convert multiline text
boxes to something easier to put in a database, and then i used
replace(chr(13), "<br>") when i needed to show the data.

I'm now working on a new version of this app, and im using C# / .NET.
Obviously I'm using the old database, but I cant find out how to do
replace(chr(13), "<br>").

Basically, what's Chr(13) in C# :o)

Cheers
Dan


Nov 18 '05 #9

P: n/a
"\n" is used in *nix systems. In DOS/Windows it should be "/r/n" I think.
(Though most software expecially browsers should have no difference, I don't
think it should be the case for database where data ought to be kept as it.

P.S.: "/r" is carriage return, "/n" is newline. They carry hex code
"0Dh"(chr(13)) and "0Ah"(chr(10)) respectively.
P.S.: "/r" is used for Apple/Mac.

"Dan Nash" <da*@musoswire.co.uk> bl
news:38**********************************@microsof t.com g...
Hi guys

Neither of those work. I think I need to actually put the ascii char 13, but im not sure how to do it. In the db it looks like a little square box! It's that I want to replace with <br>.

Any ideas?
"Chris Austin" wrote:
Dan,

I think you are looking for "\n".

-Chris
http://weblogs.austinspad.com/caustin

"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:F3**********************************@microsof t.com...
Lo,

In a previous version of an app, I used replace to convert multiline text boxes to something easier to put in a database, and then i used
replace(chr(13), "<br>") when i needed to show the data.

I'm now working on a new version of this app, and im using C# / .NET.
Obviously I'm using the old database, but I cant find out how to do
replace(chr(13), "<br>").

Basically, what's Chr(13) in C# :o)

Cheers
Dan


Nov 18 '05 #10

P: n/a
Good heavens! How about:

char thirteen = (char) 13;

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Tod1d" <no*****@netsalad.com> wrote in message
news:94**************************@posting.google.c om...
Hi Dan,

Try this :
Byte[] myBytes13 = {13};

string myStr13 = System.Text.Encoding.ASCII.GetString(myBytes13);

dbString.Replace(myStr13, "<br>")

Sorry, I did not have time to test to see if this actually works.

Tod Birdsall, MCP
http://tod1d.blogspot.com

"Dan Nash" <da*@musoswire.co.uk> wrote in message

news:<38**********************************@microso ft.com>...
Hi guys

Neither of those work. I think I need to actually put the ascii char 13, but im not sure how to do it. In the db it looks like a little square box! It's that I want to replace with <br>.

Any ideas?
"Chris Austin" wrote:
Dan,

I think you are looking for "\n".

-Chris
http://weblogs.austinspad.com/caustin

"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:F3**********************************@microsof t.com...
> Lo,
>
> In a previous version of an app, I used replace to convert multiline text > boxes to something easier to put in a database, and then i used
> replace(chr(13), "<br>") when i needed to show the data.
>
> I'm now working on a new version of this app, and im using C# / ..NET. > Obviously I'm using the old database, but I cant find out how to do
> replace(chr(13), "<br>").
>
> Basically, what's Chr(13) in C# :o)
>
> Cheers
>
>
> Dan

Nov 18 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.