2days........how to decoder
-
using(System.IO.StreamReader sr = new System.IO.StreamReader(temp_path)) { //没有到达文件结尾时一直读取文件 while(sr.Peek() > 0) { //读出一行文本 string temp_string = sr.ReadLine(); //进行编码转换,原ASCI码转换成Unicode编码 Here how to do? I tried two days but no good^^ //连接到输出文件内容中 file_context += temp_string + "
"; } } -
using(System.IO.StreamReader sr = new System.IO.StreamReader(temp_path)) { //没有到达文件结尾时一直读取文件 while(sr.Peek() > 0) { //读出一行文本 string temp_string = sr.ReadLine(); //进行编码转换,原ASCI码转换成Unicode编码 Here how to do? I tried two days but no good^^ //连接到输出文件内容中 file_context += temp_string + "
"; } }using(System.IO.StreamReader sr = new System.IO.StreamReader(temp_path)) { //没有到达文件结尾时一直读取文件 while(sr.Peek() > 0) { //读出一行文本 string temp_string = sr.ReadLine(); //convert ASCII to Unicode Here how to do? I tried two days but no good^^ //连接到输出文件内容中 file_context += temp_string + " "; } }
-
using(System.IO.StreamReader sr = new System.IO.StreamReader(temp_path)) { //没有到达文件结尾时一直读取文件 while(sr.Peek() > 0) { //读出一行文本 string temp_string = sr.ReadLine(); //进行编码转换,原ASCI码转换成Unicode编码 Here how to do? I tried two days but no good^^ //连接到输出文件内容中 file_context += temp_string + "
"; } }How to do what? If I venture to do a guess, you are trying to read a file using a specific encoding? Then you just have to specify the encoding when you create the StreamReader. You don't have to use Peek. Just use ReadLine until it returns null.
--- b { font-weight: normal; }
-
using(System.IO.StreamReader sr = new System.IO.StreamReader(temp_path)) { //没有到达文件结尾时一直读取文件 while(sr.Peek() > 0) { //读出一行文本 string temp_string = sr.ReadLine(); //进行编码转换,原ASCI码转换成Unicode编码 Here how to do? I tried two days but no good^^ //连接到输出文件内容中 file_context += temp_string + "
"; } }rainfeet wrote:
file_context += temp_string + " ";
Either do:
file_context += temp_string + @"
";-or-
file_context += temp_string + Environment.NewLine;
**
xacc.ide-0.2.0.50 - now with partial MSBuild support!
**
-
How to do what? If I venture to do a guess, you are trying to read a file using a specific encoding? Then you just have to specify the encoding when you create the StreamReader. You don't have to use Peek. Just use ReadLine until it returns null.
--- b { font-weight: normal; }
-
How to do what? If I venture to do a guess, you are trying to read a file using a specific encoding? Then you just have to specify the encoding when you create the StreamReader. You don't have to use Peek. Just use ReadLine until it returns null.
--- b { font-weight: normal; }
-
rainfeet wrote:
file_context += temp_string + " ";
Either do:
file_context += temp_string + @"
";-or-
file_context += temp_string + Environment.NewLine;
**
xacc.ide-0.2.0.50 - now with partial MSBuild support!
**
-
-
-
the source txt file is encodeing with ASCII i want to display it...with Unicode not ASCII(98 97 25 20....)
-
using(System.IO.StreamReader sr = new System.IO.StreamReader(temp_path)) { //没有到达文件结尾时一直读取文件 while(sr.Peek() > 0) { //读出一行文本 string temp_string = sr.ReadLine(); //进行编码转换,原ASCI码转换成Unicode编码 Here how to do? I tried two days but no good^^ //连接到输出文件内容中 file_context += temp_string + "
"; } }there are two ways to slove this problem. first is that after you read the bytes,then you convert it to unicode : string temp_string = sr.ReadLine(); // Create two different encodings. Encoding ascii = Encoding.ASCII; Encoding unicode = Encoding.Unicode; // Convert the string into a byte[]. byte[] assciiBytes = unicode.GetBytes(temp_string ); // Perform the conversion from one encoding to the other. byte[] unicodeBytes = Encoding.Convert(unicode, ascii, assciiBytes ); the second is that initalize the StreamReader with unicode: using(System.IO.StreamReader sr = new System.IO.StreamReader(temp_path, Encoding.Unicode)) { } Just do it!
-
Then specify the ASCII encoding when you open the StreamReader.
--- b { font-weight: normal; }
-
there are two ways to slove this problem. first is that after you read the bytes,then you convert it to unicode : string temp_string = sr.ReadLine(); // Create two different encodings. Encoding ascii = Encoding.ASCII; Encoding unicode = Encoding.Unicode; // Convert the string into a byte[]. byte[] assciiBytes = unicode.GetBytes(temp_string ); // Perform the conversion from one encoding to the other. byte[] unicodeBytes = Encoding.Convert(unicode, ascii, assciiBytes ); the second is that initalize the StreamReader with unicode: using(System.IO.StreamReader sr = new System.IO.StreamReader(temp_path, Encoding.Unicode)) { } Just do it!
-
Then specify the ASCII encoding when you open the StreamReader. how to do this? sr.CurrentEncoding??