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

I have following lines

string[] body= File.ReadLines(x).Skip(z).Take(c).ToArray();

How can i use Encoding to ASCII there??

Thank you.
Posted

Try:
C#
byte[][] lines = File.ReadLines(x).Skip(z).Take(c).Select(l => Encoding.ASCII.GetBytes(l)).ToArray();
 
Share this answer
 
Comments
OriginalGriff 25-Mar-14 3:40am    
Why? That would just convert it back to Unicode again...

What are you trying to do? Not the specific code, but why are you trying to use ASCII? What do you need it for, and what are you going to do with it?
File.ReadLine is taking second argument for Encoding Type.

So your code must be -
C#
string[] body = File.ReadLines(x,Encoding.ASCII).Skip(z).Take(c).ToArray();


But if you want to read special characters then -
C#
string[] body = File.ReadLines(x,Encoding.UTF8).Skip(z).Take(c).ToArray();


Hope this will help you...
 
Share this answer
 
v2
Comments
Punamchand Dhuppad 25-Mar-14 3:39am    
It means that your file has special characters and it is save in UTF 8 format. But if you want to read special characters then use Encoding.UTF8 type in second argument.

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