AspNet.sk     Diskusné fóra     Vitajte v QuickStarts     ASP.NET     Silverlight     Ako môžem...? (en)     Class prehliadač Príklady chcem v ...   
Menu
Skip Navigation Links.

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Use different text encodings?



This sample illustrates how to use multiple encoding formats available from the System.Text namespace. A StreamWriter object is created and passed a Stream object along with an Encoding object from the System.Text namespace. Once created, any output method calls on the StreamWriter object will be written in the specified encoding.


Dim Fs As FileStream = New FileStream("text.txt", FileMode.OpenOrCreate)
 ...
Dim T As StreamWriter = New StreamWriter (Fs, Encoding.UTF8)
T.Write("This is in UTF8")
VB


A StreamReader object is used to read text in a given encoding and is constructed in the same manner as a StreamWriter object.


Dim Fs As FileStream = New FileStream("text.txt", FileMode.Open)
 ...
Dim T As StreamReader = New StreamReader(Fs, Encoding.UTF8)
Dim S As String = T.ReadLine()
VB


The following example illustrates creating StreamWriter objects of different encodings and using each object to write to a text file.

Example

VB Encoding.exe
View Source

[This sample can be found at H:\Home\WU_000036_efe47225c86ca62f325a01d8519bc002\Webs\aspnet.sk\quickstarts\QuickStartv20\howto\samples\globalization\encoding\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]




Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.


Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright © 2005 Microsoft Corporation. All rights reserved.
Preklad do slovenského jazyka - Copyright © 2005 - 2007 www.aspnet.sk, www.qsh.sk
Pošlite komentár k tejto stránke
Copyright © 2002 - 2008 Chastia, spol. s r. o., Igor Stanek, Designed by Lacino
Portál je hostovaný na serveroch firmy Quantasoft - www.qsh.sk.