Jedi Master Spooky
Jedi Master Spooky

Reputation: 5819

System.IO.StreamWrite and Spanish Characters

I need to write the following string to a txt a File:

SEGS,AUS1,1,0,0,712205,584,8659094,2,NUÑEZ FELIX ARTURO,584

I when I use:

using  (System.IO.StreamWriter sw = new System.IO.StreamWriter(@fileSobrantes, true)) {
       sw.WriteLine("SEGS,AUS1,1,0,0,712205,584,8659094,2,NUÑEZ   FELIX ARTURO,584");
}

I get this in the file

SEGS,AUS1,1,0,0,712205,584,8659094,2,NUÑEZ FELIX ARTURO,584

I try with the Encoding parameters in ASCII, UNICODE and ALL UTF and does not work.

System.IO.StreamWriter(@fileSobrantes, true,Encoding.UTF32 ))

Upvotes: 0

Views: 1944

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1502376

You can't easily (and accurately) represent what you get in the file without giving a hex dump. What are you trying to use to read the file? My guess is that if you try Encoding.Default that will work for you, but it's hard to say for sure without knowing what you're trying to use to read it.

The other alternative is that your source string is incorrect. If you've really got it as a string literal in your source code, are you sure you've got Visual Studio set up to interpret it correctly?

See my unicode debugging page for suggested techniques.

EDIT: By the way, why are you prefixing fileSobrantes with @? For identifiers you only need to do that if they're keywords. You may be getting confused with verbatim string literals - but this isn't a string literal, it's a variable name.

Upvotes: 1

Related Questions