Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i write a c# program which read txt files and print it.
my text files like:
<br />
Hi\r\nMy Name is


but when i try to print i can't see the result like:
Hi
My Name is


how can i fix this problem?

What I have tried:

i tried removing \r,\n and looking the web
Posted
Updated 21-Feb-16 23:13pm
v2
Comments
Jawad Ahmed Tanoli 22-Feb-16 3:39am    
show some code
Member 10525430 22-Feb-16 3:43am    
A.txt:
D/Hi\r\nMy Name is
C#:
string[] Text = Regex.Split(lines[i], "D/");
"I split the txt lines from D/"
MessageBox.Show(Text[1]);
Text[0]=D/
Text[1]=Hi\r\nMy Name is
and messagebox's message is "Hi\r\nMy Name is"
Maciej Los 22-Feb-16 4:25am    
Richard MacCutchan 22-Feb-16 4:30am    
I just tried that and it works fine. You need to edit your question and show all the exact code that you are using.
Member 10525430 22-Feb-16 4:48am    
but i dont want to show messagebox Hi\r\nMy Name is
i want
Hi
My Name is

C#
string contents = File.ReadAllText(@"C:\test.txt");
            MessageBox.Show(contents);
 
Share this answer
 
Comments
Member 10525430 22-Feb-16 3:58am    
message box show "Hi\r\nMy Name is"
Please, read my comments to the question. I think your file is broken. \r and \n switches are non-printable signs and shouldn't be visible.
See: Strings (C# Programming Guide)[^]


Check this:
C#
string s = "Hi\r\nMy name is Maciej";

File.WriteAllText(@"D:\s.txt",s);

s = File.ReadAllText(@"D:\s.txt");
Console.WriteLine(s);


It prints:
Hi
My name is Maciej
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900