■ Encoding 클래스에서 대체(fallback) 메커니즘을 사용하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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); |