■ Encoding 클래스 : 대체(fallback) 메커니즘 사용하기

------------------------------------------------------------------------------------------------------------------------

using System;

using System.Text;

 

Encoding sourceEncoding = Encoding.Unicode;

 

string sourceText = "샾";

 

byte[] sourceByteArray = Encoding.Unicode.GetBytes(sourceText);

 

Encoding targetEncoding = Encoding.GetEncoding("euc-kr", new EncoderReplacementFallback("*"), new DecoderReplacementFallback("*"));

 

byte[] targetByteArray = Encoding.Convert(sourceEncoding, targetEncoding, sourceByteArray);

 

string targetText = targetEncoding.GetString(targetByteArray);

 

Console.WriteLine("SOURCE TEXT : {0}", sourceText);

Console.WriteLine("TARGET TEXT : {0}", targetText);

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG