当前位置: 首页>>代码示例>>C#>>正文


C# Encoding.GetDecoder方法代码示例

本文整理汇总了C#中Encoding.GetDecoder方法的典型用法代码示例。如果您正苦于以下问题:C# Encoding.GetDecoder方法的具体用法?C# Encoding.GetDecoder怎么用?C# Encoding.GetDecoder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Encoding的用法示例。


在下文中一共展示了Encoding.GetDecoder方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DecodeContent

    public static string DecodeContent(byte[] byteInput, Encoding enc)
    {
        Decoder decoder = enc.GetDecoder();
        char[] chars = new char[byteInput.Length];
        byte[] bytes = new byte[byteInput.Length * 4];

        bool completed = false;
        int byteIndex = 0;
        int bytesUsed;
        int charsUsed;
        bool flush = false;

        decoder.Convert(byteInput, byteIndex, byteInput.Length,
                        chars, 0, byteInput.Length, flush,
                        out bytesUsed, out charsUsed, out completed);
        return new string(chars);
    }
开发者ID:dstepanov25,项目名称:Suza,代码行数:17,代码来源:PageEncoding.cs

示例2: ValidateSerializeDeserialize

partial         static void ValidateSerializeDeserialize(Encoding e)
        {
            // Make sure the Encoding roundtrips
            Assert.Equal(e, BinaryFormatterHelpers.Clone(e));

            // Get an encoder and decoder from the encoding, and clone them
            Encoder origEncoder = e.GetEncoder();
            Decoder origDecoder = e.GetDecoder();
            Encoder clonedEncoder = BinaryFormatterHelpers.Clone(origEncoder);
            Decoder clonedDecoder = BinaryFormatterHelpers.Clone(origDecoder);

            // Encode and decode some text with each pairing
            const string InputText = "abcdefghijklmnopqrstuvwxyz";
            char[] inputTextChars = InputText.ToCharArray();
            var pairs = new[]
            {
                Tuple.Create(origEncoder, origDecoder),
                Tuple.Create(origEncoder, clonedDecoder),
                Tuple.Create(clonedEncoder, origDecoder),
                Tuple.Create(clonedEncoder, clonedDecoder),
            };
            var results = new List<char[]>();
            foreach (Tuple<Encoder, Decoder> pair in pairs)
            {
                byte[] encodedBytes = new byte[pair.Item1.GetByteCount(inputTextChars, 0, inputTextChars.Length, true)];
                Assert.Equal(encodedBytes.Length, pair.Item1.GetBytes(inputTextChars, 0, inputTextChars.Length, encodedBytes, 0, true));
                char[] decodedChars = new char[pair.Item2.GetCharCount(encodedBytes, 0, encodedBytes.Length)];
                Assert.Equal(decodedChars.Length, pair.Item2.GetChars(encodedBytes, 0, encodedBytes.Length, decodedChars, 0));
                results.Add(decodedChars);
            }

            // Validate that all of the pairings produced the same results
            foreach (char[] a in results)
            {
                foreach (char[] b in results)
                {
                    Assert.Equal(a, b);
                }
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:40,代码来源:EncodingCodePages.netstandard17.cs

示例3: DecodeByteArryToString

 /// <summary>
 /// Converts byte array to string, using decoding as requested
 /// </summary>
 public string DecodeByteArryToString(byte[] ByteArry, Encoding ByteEncoding)
 {
     if (ByteArry == null)
     {
         //no bytes to convert
         return null;
     }
     Decoder byteArryDecoder;
     if (ByteEncoding == null)
     {
         //no encoding indicated. Let's try UTF7
         System.Diagnostics.Debugger.Break(); //didn't have a sample email to test this
         byteArryDecoder = Encoding.UTF7.GetDecoder();
     }
     else
     {
         byteArryDecoder = ByteEncoding.GetDecoder();
     }
     int charCount = byteArryDecoder.GetCharCount(ByteArry, 0, ByteArry.Length);
     char[] bodyChars = new char[charCount - 1+ 1];
     int charsDecodedCount = byteArryDecoder.GetChars(ByteArry, 0, ByteArry.Length, bodyChars, 0);
     //convert char[] to string
     return new string(bodyChars);
 }
开发者ID:okyereadugyamfi,项目名称:softlogik,代码行数:27,代码来源:Pop3MimeClient.cs

示例4: HtmlStream

        public HtmlStream(Stream stm, Encoding defaultEncoding) {
            if(defaultEncoding == null) {
                defaultEncoding = Encoding.UTF8; // default is UTF8
            }
            if(!stm.CanSeek) {
                // Need to be able to seek to sniff correctly.
                stm = CopyToMemoryStream(stm);
            }
            this.stm = stm;
            rawBuffer = new Byte[BUFSIZE];
            rawUsed = stm.Read(rawBuffer, 0, 4); // maximum byte order mark
            this.m_buffer = new char[BUFSIZE];

            // Check byte order marks
            this.m_decoder = AutoDetectEncoding(rawBuffer, ref rawPos, rawUsed);
            var bom = rawPos;
            if(this.m_decoder == null) {
                this.m_decoder = defaultEncoding.GetDecoder();
                rawUsed += stm.Read(rawBuffer, 4, BUFSIZE - 4);
                DecodeBlock();
                // Now sniff to see if there is an XML declaration or HTML <META> tag.
                var sd = SniffEncoding();
                if(sd != null) {
                    this.m_decoder = sd;
                }
            }

            // Reset to get ready for Read()
            this.stm.Seek(0, SeekOrigin.Begin);
            this.pos = this.used = 0;
            // skip bom
            if(bom > 0) {
                stm.Read(this.rawBuffer, 0, bom);
            }
            this.rawPos = this.rawUsed = 0;
        }
开发者ID:roomaroo,项目名称:coapp.powershell,代码行数:36,代码来源:SgmlParseException.cs

示例5: DecoderTest

	public DecoderTest (string cnvout, Encoding encoding) : base (cnvout)
	{
		dec = encoding.GetDecoder ();
	}
开发者ID:killabytenow,项目名称:mono-System.Text.UTF8Encoding-test,代码行数:4,代码来源:convert.cs

示例6: EndianBinaryReader

    /// <summary>
    /// Constructs a new binary reader with the given bit converter, reading
    /// to the given stream, using the given encoding.
    /// </summary>
    /// <param name="bitConverter">Converter to use when reading data</param>
    /// <param name="stream">Stream to read data from</param>
    /// <param name="encoding">Encoding to use when reading character data</param>
    public EndianBinaryReader(EndianBitConverter bitConverter, Stream stream, Encoding encoding)
    {
        if (bitConverter == null)
            {
                throw new ArgumentNullException("bitConverter");
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }
            if (!stream.CanRead)
            {
                throw new ArgumentException("Stream isn't writable", "stream");
            }
            this.stream = stream;
            this.bitConverter = bitConverter;
            this.encoding = encoding;
            this.decoder = encoding.GetDecoder();
            this.minBytesPerChar = 1;

            if (encoding is UnicodeEncoding)
            {
                minBytesPerChar = 2;
            }
    }
开发者ID:RaviChimmalgi,项目名称:fishbowl-shopify,代码行数:36,代码来源:BigEndianReader.cs


注:本文中的Encoding.GetDecoder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。