How to Open a File in Text-mode?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

It is that in Traditional C++ ,the Class "file" has a Open Method which can
specify opening a file in Text-Mode.

The Text-Mode can automaticaly Convert "\r\n" to "\n" (\13 \10 to \10).

But,I can not find a way to do this in Extention Managed C++.Net ?

Any new Solution?
 
First thank you,

Then,

I use the following code to try

[
//FileStream * theFile

StreamReader * FileReader = new StreamReader(theFile,Encoding::Unicode);
String * sTemp = FileReader->ReadToEnd();

Encoding * unicode = Encoding::Unicode;

FileReader->Close();

FileBuffer = new unsigned char __gc[sTemp->Length +1];
FileBuffer = unicode->GetBytes(sTemp);
FileBuffer[sTemp->Length] = '\0';
]

I notice that the double-byte Charactor is converted to two single-byte
Charactors as 8-bit usigned char . East Asia Language is converted to 0x7F+
Charactors. It works perfectly.

But the converting of "\13\10" to "\10" does not happen....


What's the correct solution of this?
Will you please give out some code?
=========================================================================

“Kevin Spencerâ€ç¼–写:
 
But the converting of "\13\10" to "\10" does not happen....
What's the correct solution of this?
Why not just replace every "\13\10" with "\10" after loading the file?
 
I don't believe there's any built-in mechanism for this. The
StreamReader.ReadLine method will read up to a CR or CR/LF combination, and
not read the line terminator sequence. So you could use this method, and
append the appropriate line terminator, or you could simply replace for the
whole string (which is what I think I would do).

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

?? said:
First thank you,

Then,

I use the following code to try

[
//FileStream * theFile

StreamReader * FileReader = new StreamReader(theFile,Encoding::Unicode);
String * sTemp = FileReader->ReadToEnd();

Encoding * unicode = Encoding::Unicode;

FileReader->Close();

FileBuffer = new unsigned char __gc[sTemp->Length +1];
FileBuffer = unicode->GetBytes(sTemp);
FileBuffer[sTemp->Length] = '\0';
]

I notice that the double-byte Charactor is converted to two single-byte
Charactors as 8-bit usigned char . East Asia Language is converted to
0x7F+
Charactors. It works perfectly.

But the converting of "\13\10" to "\10" does not happen....


What's the correct solution of this?
Will you please give out some code?
=========================================================================

"Kevin Spencer"??:
See the System.Encoding class:

http://msdn.microsoft.com/library/d...ef/html/frlrfsystemtextencodingclasstopic.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
 
The String::Replace works

But I did not think .NET is so stiff in this aspect , I would rather use C
Library Function to make this.

A litte dispaired to .NET

Thank you all.
 
Back
Top