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


C# Encoding.GetString方法代码示例

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


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

示例1: GetString

 public static void GetString(Encoding encoding, byte[] bytes, int index, int count, string expected)
 {
     if (index == 0 && count == bytes.Length)
     {
         // Use GetString(byte[])
         Assert.Equal(expected, encoding.GetString(bytes));
     }
     // Use GetString(byte[], int, int)
     Assert.Equal(expected, encoding.GetString(bytes, index, count));
 }
开发者ID:eerhardt,项目名称:corefx,代码行数:10,代码来源:EncodingTestHelpers.cs

示例2: TestEncoding

 private void TestEncoding(Encoding enc, int byteCount, int maxByteCount, byte[] bytes)
 {
     Assert.Equal(byteCount, enc.GetByteCount(s_myChars));
     Assert.Equal(maxByteCount, enc.GetMaxByteCount(s_myChars.Length));
     Assert.Equal(enc.GetBytes(s_myChars), bytes);
     Assert.Equal(enc.GetCharCount(bytes), s_myChars.Length);
     Assert.Equal(enc.GetChars(bytes), s_myChars);
     Assert.Equal(enc.GetString(bytes, 0, bytes.Length), s_myString);
     Assert.NotEqual(0, enc.GetHashCode());
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:ConvertUnicodeEncodings.cs

示例3: ReadStringAsync

	public static async Task<string> ReadStringAsync(this IUVStream stream, Encoding encoding)
	{
		if (encoding == null) {
			throw new ArgumentException("encoding");
		}
		var buffer = await stream.ReadAsync();
		if (buffer == null) {
			return null;
		}
		return encoding.GetString(buffer.Buffer, buffer.Start, buffer.Length);
	}
开发者ID:oskarwkarlsson,项目名称:LibuvSharp,代码行数:11,代码来源:Async.cs

示例4: ReadStringAsync

	public static async Task<string> ReadStringAsync(this IUVStream<ArraySegment<byte>> stream, Encoding encoding)
	{
		if (encoding == null) {
			throw new ArgumentException("encoding");
		}
		var buffer = await stream.ReadStructAsync();
		if (!buffer.HasValue) {
			return null;
		}
		return encoding.GetString(buffer.Value);
	}
开发者ID:lrdcasimir,项目名称:LibuvSharp,代码行数:11,代码来源:Common.cs

示例5: ReadStringAsync

	public static async Task<string> ReadStringAsync(this IUVStream stream, Encoding encoding)
	{
		if (encoding == null) {
			throw new ArgumentException("encoding");
		}
		var buffer = await stream.ReadAsync();
		if (!buffer.HasValue) {
			return null;
		}
		var b = buffer.Value;
		return encoding.GetString(b.Array, b.Offset, b.Count);
	}
开发者ID:GamingAtheist,项目名称:LibuvSharp,代码行数:12,代码来源:Async.cs

示例6: ToStringFull

    public static String ToStringFull(this XDocument That, Encoding Encoding)
    {
        var VersionXmlStream = new MemoryStream();
        var VersionXmlWriter = XmlWriter.Create(VersionXmlStream, new XmlWriterSettings()
        {
            Encoding = Encoding,
            Indent = true,
        });
        That.WriteTo(VersionXmlWriter);
        VersionXmlWriter.Flush();

        return Encoding.GetString(VersionXmlStream.ToArray());
    }
开发者ID:e-COS,项目名称:cspspemu,代码行数:13,代码来源:LinqXmlExExtensions.cs

示例7: read

            public static string read(Stream s, long count, Encoding enc)
            {
                string str = "";
                while (count > 0)
                {
                    byte[] buffer = new byte[1];
                    try
                    {
                        s.Read(buffer, 0, 1);
                    }
                    catch
                    {
                        return null;
                    }

                    str += enc.GetString(buffer);
                    count--;
                }
                return str;
            }
开发者ID:FihlaTV,项目名称:conference,代码行数:20,代码来源:Utility.Parser.cs

示例8: Load

 public int Load(string path, Encoding encode)
 {
     try
     {
         FileStream fs = new FileStream(Application.persistentDataPath + "/" + path, FileMode.Open, FileAccess.Read);
         BinaryReader br = new BinaryReader(fs);
         var bin = new System.Collections.Generic.List<byte>();
         try
         {
             while (true) { bin.Add(br.ReadByte()); }
         }
         catch (EndOfStreamException) { }
         str = encode.GetString(aes.Decrypt(bin.ToArray()));
         br.Close();
     }
     catch {
         // ロード失敗
         return -1;
     }
     return 0;
 }
开发者ID:GotoK,项目名称:H401,代码行数:21,代码来源:FileLoader.cs

示例9: DecompressGZip

 /// <summary>
 ///     A byte[] extension method that decompress the byte array gzip to string.
 /// </summary>
 /// <param name="this">The @this to act on.</param>
 /// <param name="encoding">The encoding.</param>
 /// <returns>The byte array gzip to string.</returns>
 public static string DecompressGZip(this byte[] @this, Encoding encoding)
 {
     const int bufferSize = 1024;
     using (var memoryStream = new MemoryStream(@this))
     {
         using (var zipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
         {
             // Memory stream for storing the decompressed bytes
             using (var outStream = new MemoryStream())
             {
                 var buffer = new byte[bufferSize];
                 int totalBytes = 0;
                 int readBytes;
                 while ((readBytes = zipStream.Read(buffer, 0, bufferSize)) > 0)
                 {
                     outStream.Write(buffer, 0, readBytes);
                     totalBytes += readBytes;
                 }
                 return encoding.GetString(outStream.GetBuffer(), 0, totalBytes);
             }
         }
     }
 }
开发者ID:fqybzhangji,项目名称:Z.ExtensionMethods,代码行数:29,代码来源:ByteArray.DecompressGZip.cs

示例10: ValidateConsoleEncoding

    public static unsafe void ValidateConsoleEncoding(Encoding encoding)
    {
        Assert.NotNull(encoding);
        // The primary purpose of ConsoleEncoding is to return an empty preamble.
        Assert.Equal(Array.Empty<byte>(), encoding.GetPreamble());

        // There's not much validation we can do, but we can at least invoke members
        // to ensure they don't throw exceptions as they delegate to the underlying
        // encoding wrapped by ConsoleEncoding.

        Assert.False(string.IsNullOrWhiteSpace(encoding.EncodingName));
        Assert.False(string.IsNullOrWhiteSpace(encoding.WebName));
        Assert.True(encoding.CodePage >= 0);
        bool ignored = encoding.IsSingleByte;

        // And we can validate that the encoding is self-consistent by roundtripping
        // data between chars and bytes.

        string str = "This is the input string.";
        char[] strAsChars = str.ToCharArray();
        byte[] strAsBytes = encoding.GetBytes(str);
        Assert.Equal(strAsBytes.Length, encoding.GetByteCount(str));
        Assert.True(encoding.GetMaxByteCount(str.Length) >= strAsBytes.Length);

        Assert.Equal(str, encoding.GetString(strAsBytes));
        Assert.Equal(str, encoding.GetString(strAsBytes, 0, strAsBytes.Length));
        Assert.Equal(str, new string(encoding.GetChars(strAsBytes)));
        Assert.Equal(str, new string(encoding.GetChars(strAsBytes, 0, strAsBytes.Length)));
        fixed (byte* bytesPtr = strAsBytes)
        {
            char[] outputArr = new char[encoding.GetMaxCharCount(strAsBytes.Length)];

            int len = encoding.GetChars(strAsBytes, 0, strAsBytes.Length, outputArr, 0);
            Assert.Equal(str, new string(outputArr, 0, len));
            Assert.Equal(len, encoding.GetCharCount(strAsBytes));
            Assert.Equal(len, encoding.GetCharCount(strAsBytes, 0, strAsBytes.Length));

            fixed (char* charsPtr = outputArr)
            {
                len = encoding.GetChars(bytesPtr, strAsBytes.Length, charsPtr, outputArr.Length);
                Assert.Equal(str, new string(charsPtr, 0, len));
                Assert.Equal(len, encoding.GetCharCount(bytesPtr, strAsBytes.Length));
            }

            Assert.Equal(str, encoding.GetString(bytesPtr, strAsBytes.Length));
        }

        Assert.Equal(strAsBytes, encoding.GetBytes(strAsChars));
        Assert.Equal(strAsBytes, encoding.GetBytes(strAsChars, 0, strAsChars.Length));
        Assert.Equal(strAsBytes.Length, encoding.GetByteCount(strAsChars));
        Assert.Equal(strAsBytes.Length, encoding.GetByteCount(strAsChars, 0, strAsChars.Length));
        fixed (char* charsPtr = strAsChars)
        {
            Assert.Equal(strAsBytes.Length, encoding.GetByteCount(charsPtr, strAsChars.Length));

            byte[] outputArr = new byte[encoding.GetMaxByteCount(strAsChars.Length)];
            Assert.Equal(strAsBytes.Length, encoding.GetBytes(strAsChars, 0, strAsChars.Length, outputArr, 0));
            fixed (byte* bytesPtr = outputArr)
            {
                Assert.Equal(strAsBytes.Length, encoding.GetBytes(charsPtr, strAsChars.Length, bytesPtr, outputArr.Length));
            }
            Assert.Equal(strAsBytes.Length, encoding.GetBytes(str, 0, str.Length, outputArr, 0));
        }
    }
开发者ID:ESgarbi,项目名称:corefx,代码行数:64,代码来源:ReadAndWrite.cs

示例11: af_ReadAllText

	public static String af_ReadAllText(String path, Encoding encoding)
	{
		return encoding.GetString(af_ReadAllBytes(path));
	}
开发者ID:fengqk,项目名称:Art,代码行数:4,代码来源:AFileWrapper.cs

示例12: UrlDecode

 /// <summary>
 /// 
 /// </summary>
 /// <param name="s">�f�R�[�h���镶����</param>
 /// <param name="enc">�G���R�[�f�B���O</param>
 /// <returns></returns>
 public static string UrlDecode(string s, Encoding enc)
 {
     List<byte> bytes = new List<byte>();
     for (int i = 0; i < s.Length; i++)
     {
         char c = s[i];
         if (c == '%')
             bytes.Add(byte.Parse(s[++i].ToString() + s[++i].ToString()));
         else if (c == '+')
             bytes.Add((byte)0x20);
         else
             bytes.Add((byte)c);
     }
     return enc.GetString(bytes.ToArray(), 0, bytes.Count);
 }
开发者ID:anon5r,项目名称:TSLoginManager,代码行数:21,代码来源:ProgramController.cs

示例13: ByteArrayToString

 public static string ByteArrayToString(byte[] ByteArray, Encoding encoding)
 {
     return encoding.GetString(ByteArray);
 }
开发者ID:hhrhzy,项目名称:mywork,代码行数:4,代码来源:Network.cs

示例14: Dump

        /// <summary>
        /// Prints all pending messages to the console.
        /// </summary>
        /// <param name="socket">ZMQ Socket</param>
        /// <param name="encoding">Encoding to use for message decoding</param>
        public static void Dump(Socket socket, Encoding encoding) {
            if (socket == null) {
                throw new ArgumentNullException("socket");
            }

            Console.WriteLine(new String('-', 38));
            foreach (byte[] msg in socket.RecvAll()) {
                Console.Write("[{0}] ", String.Format("{0:d3}", msg.Length));
                if (msg.Length == 17 && msg[0] == 0) {
                    Console.WriteLine(DecodeUUID(msg).Substring(1));
                }
                else {
                    Console.WriteLine(encoding.GetString(msg, 0, msg.Length));
                }
            }
        }
开发者ID:castlestronghold,项目名称:clrzmq2,代码行数:21,代码来源:Util.cs

示例15: GetDynamicJsonObject

 public static dynamic GetDynamicJsonObject(byte[] buf, Encoding encoding)
 {
     return GetDynamicJsonObject(encoding.GetString(buf));
 }
开发者ID:Rumel,项目名称:Radabite,代码行数:4,代码来源:JsonUtils.cs


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