C# equiv of Chr(13)

G

Guest

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# :eek:)

Cheers


Dan
 
G

Guest

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?
 
B

bruce barker

in c#

"\r" = chr(13)
"\n" = chr(10)


mystring.Replace("\r","<br>");

-- bruce (sqlwork.com)
 
C

Chris Austin

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
 
T

Tod1d

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
 
L

Lau Lei Cheong

"\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.
 
K

Kevin Spencer

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 said:
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" <[email protected]> wrote in message
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?
 
Joined
Jul 19, 2007
Messages
1
Reaction score
0
char in c#

vb 6.0
Chr(13)

c# equivalent is

(char)13;

Example;

string xx= (char)13+ "hello"+(char)13;
 
Joined
Feb 22, 2010
Messages
1
Reaction score
0
Chr(13) c# equivalent

Char[] SplitCharacters = new Char[6];
SplitCharacters[0] = ',';
SplitCharacters[1] = (char)13;
SplitCharacters[2] = ' ';
SplitCharacters[3] = (char)10;
SplitCharacters[4] = (char)11;
SplitCharacters[5] = (char)12;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top