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


C# UTF8Encoding类代码示例

本文整理汇总了C#中UTF8Encoding的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding类的具体用法?C# UTF8Encoding怎么用?C# UTF8Encoding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        // Add your scenario description here
        TestLibrary.TestFramework.BeginScenario("PosTest1: Verify method GetByteCount with a non-null Byte[]");

        try
        {
            Byte[] bytes = new Byte[] {
                                         85,  84,  70,  56,  32,  69, 110,
                                         99, 111, 100, 105, 110, 103,  32,
                                         69, 120,  97, 109, 112, 108, 101};

            UTF8Encoding utf8 = new UTF8Encoding();
            int charCount = utf8.GetCharCount(bytes, 2, 8);

            if (charCount != 8)
            {
                TestLibrary.TestFramework.LogError("001.1", "Method GetByteCount Err.");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:32,代码来源:utf8encodinggetcharcount.cs

示例2: Mockfile_Create_OverwritesExistingFile

        public void Mockfile_Create_OverwritesExistingFile()
        {
            string path = XFS.Path(@"c:\some\file.txt");
            var fileSystem = new MockFileSystem();

            var mockFile = new MockFile(fileSystem);

            fileSystem.Directory.CreateDirectory(Path.GetDirectoryName(path));

            // Create a file
            using (var stream = mockFile.Create(path))
            {
                var contents = new UTF8Encoding(false).GetBytes("Test 1");
                stream.Write(contents, 0, contents.Length);
            }

            // Create new file that should overwrite existing file
            var expectedContents = new UTF8Encoding(false).GetBytes("Test 2");
            using (var stream = mockFile.Create(path))
            {
                stream.Write(expectedContents, 0, expectedContents.Length);
            }

            var actualContents = fileSystem.GetFile(path).Contents;

            Assert.That(actualContents, Is.EqualTo(expectedContents));
        }
开发者ID:BrianLanghoor,项目名称:System.IO.Abstractions,代码行数:27,代码来源:MockFileCreateTests.cs

示例3: PosTest1

 public void PosTest1()
 {
     String chars = "UTF8 Encoding Example";
     UTF8Encoding utf8 = new UTF8Encoding();
     int byteCount = utf8.GetByteCount(chars);
     Assert.Equal(chars.Length, byteCount);
 }
开发者ID:eerhardt,项目名称:corefx,代码行数:7,代码来源:UTF8EncodingGetByteCount2.cs

示例4: PosTest2

 public void PosTest2()
 {
     String chars = "";
     UTF8Encoding utf8 = new UTF8Encoding();
     int byteCount = utf8.GetByteCount(chars);
     Assert.Equal(0, byteCount);
 }
开发者ID:eerhardt,项目名称:corefx,代码行数:7,代码来源:UTF8EncodingGetByteCount2.cs

示例5: PosTest2

 public void PosTest2()
 {
     Byte[] bytes = new Byte[] { };
     UTF8Encoding utf8 = new UTF8Encoding();
     int charCount = utf8.GetCharCount(bytes, 0, 0);
     Assert.Equal(0, charCount);
 }
开发者ID:eerhardt,项目名称:corefx,代码行数:7,代码来源:UTF8EncodingGetCharCount.cs

示例6: Post

	public virtual void Post(string url, Dictionary<string, string> data, System.Action<HttpResult> onResult) {
	
		this.MakeRequest(url, HttpMethods.POST, onResult, (r) => {

			JSONObject js = new JSONObject(data);
			var requestPayload = js.ToString();

			UTF8Encoding encoding = new UTF8Encoding();
			r.ContentLength = encoding.GetByteCount(requestPayload);
			r.Credentials = CredentialCache.DefaultCredentials;
			r.Accept = "application/json";
			r.ContentType = "application/json";
			
			//Write the payload to the request body.
			using ( Stream requestStream = r.GetRequestStream())
			{
				requestStream.Write(encoding.GetBytes(requestPayload), 0,
				                    encoding.GetByteCount(requestPayload));
			}

			return false;

		});

	}
开发者ID:amanita-main,项目名称:Unity3d.UI.Windows,代码行数:25,代码来源:HttpRequest.cs

示例7: Encrypt

 // Token: 0x06000EF7 RID: 3831 RVA: 0x00045348 File Offset: 0x00043548
 public static string Encrypt(string unencrypted)
 {
     RijndaelManaged rijndaelManaged = new RijndaelManaged();
     ICryptoTransform encryptor = rijndaelManaged.CreateEncryptor(SimpleAES.key, SimpleAES.vector);
     UTF8Encoding uTF8Encoding = new UTF8Encoding();
     return Convert.ToBase64String(SimpleAES.Encrypt(uTF8Encoding.GetBytes(unencrypted), encryptor));
 }
开发者ID:interrupt21h,项目名称:twodots_decrypt,代码行数:8,代码来源:SimpleAES_encrypt.cs

示例8: DecryptRijndael

    public static string DecryptRijndael(string encryptedString)
    {
        byte[] encrypted;

        byte[] fromEncrypted;

        UTF8Encoding utf8Converter = new UTF8Encoding();

        encrypted = Convert.FromBase64String(encryptedString);

        RijndaelManaged myRijndael = new RijndaelManaged();

        ICryptoTransform decryptor = myRijndael.CreateDecryptor(Key, IV);

        MemoryStream ms = new MemoryStream(encrypted);

        CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read);

        fromEncrypted = new byte[encrypted.Length];

        cs.Read(fromEncrypted, 0, fromEncrypted.Length);

        string decryptedString = utf8Converter.GetString(fromEncrypted);
        int indexNull = decryptedString.IndexOf("\0");
        if (indexNull > 0)
        {
            decryptedString = decryptedString.Substring(0, indexNull);
        }
        return decryptedString;
    }
开发者ID:ivladyka,项目名称:OurTravels,代码行数:30,代码来源:Encrypt.cs

示例9: get_uft8

 public static string get_uft8(string unicodeString)
 {
     UTF8Encoding utf8 = new UTF8Encoding();
     byte[] encodedBytes = utf8.GetBytes(unicodeString);
     string decodedString = utf8.GetString(encodedBytes);
     return decodedString;
 }
开发者ID:Blavtes,项目名称:JsonConfigForUnity,代码行数:7,代码来源:HelpPanel.cs

示例10: Decrypt

 // Token: 0x06000EF8 RID: 3832 RVA: 0x00045384 File Offset: 0x00043584
 public static string Decrypt(string encrypted)
 {
     RijndaelManaged rijndaelManaged = new RijndaelManaged();
     ICryptoTransform decryptor = rijndaelManaged.CreateDecryptor(SimpleAES.key, SimpleAES.vector);
     UTF8Encoding uTF8Encoding = new UTF8Encoding();
     return uTF8Encoding.GetString(SimpleAES.Decrypt(Convert.FromBase64String(encrypted), decryptor));
 }
开发者ID:interrupt21h,项目名称:twodots_decrypt,代码行数:8,代码来源:SimpleAES_encrypt.cs

示例11: getHtml

    /// <summary>
    /// Private accessor for all GET and POST requests.
    /// </summary>
    /// <param name="url">Web url to be accessed.</param>
    /// <param name="post">Place POST request information here. If a GET request, use null. </param>
    /// <param name="attempts"># of attemtps before sending back an empty string.</param>
    /// <returns>Page HTML if access was successful, otherwise will return a blank string. </returns>
    private String getHtml(String url, String post, int attempts)
    {
        WebClient webClient = new WebClient();
            UTF8Encoding utfObj = new UTF8Encoding();
            byte[] reqHTML;

            while (attempts > 0)// Will keep trying to access until attempts reach zero.
            {
                try
                {
                    if (post != null) //If post is null, then no post request is required.
                        reqHTML = webClient.UploadData(url, "POST", System.Text.Encoding.ASCII.GetBytes(post));
                    else
                        reqHTML = webClient.DownloadData(url);
                    String input = utfObj.GetString(reqHTML);
                    return input;
                }
                catch (WebException e)
                {
                    errorLog.WriteMessage("Could not contact to " + url + "  -  " + e.Message);
                    Thread.Sleep(2000);
                }
                catch (ArgumentNullException e)
                {
                    errorLog.WriteMessage("Could not retrieve data from " + url + "  -  " + e.Message);
                    Thread.Sleep(2000);
                }
                attempts--;
            }
            return "";
    }
开发者ID:JDrosdeck,项目名称:2Sprout-Windows,代码行数:38,代码来源:GetHtml.cs

示例12: PosTest1

        public void PosTest1()
        {
            UTF8Encoding UTF8NoPreamble = new UTF8Encoding();
            Byte[] preamble;

            preamble = UTF8NoPreamble.GetPreamble();
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:UTF8EncodingGetPreamble.cs

示例13: In

    public void In(
      [FriendlyName("Key", "The string to be used to check against the provided SHA1 hash.")]
      string Key,
      
      [FriendlyName("SHA1 Hash", "The SHA1 Hash to check the key against.")]
      string Hash
      )
    {
        if (Key != "" && Hash != "")
          {
         UTF8Encoding ue = new UTF8Encoding();
         byte[] bytes = ue.GetBytes(Key);

         // encrypt bytes
         SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
         byte[] hashBytes = sha1.ComputeHash(bytes);

         // Convert the encrypted bytes back to a string (base 16)
         string tmpHash = "";

         for (int i = 0; i < hashBytes.Length; i++)
         {
            tmpHash += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
         }

         string finalHash = tmpHash.PadLeft(32, '0');

         if (finalHash == Hash)
         {
            m_GoodHash = true;
         }
          }
    }
开发者ID:Oxy949,项目名称:Obscended,代码行数:33,代码来源:uScriptAct_CheckSHA1Hash.cs

示例14: ToDataSet

    public static DataSet ToDataSet(DataSetData dsd)
    {
        DataSet ds = new DataSet();
        UTF8Encoding encoding = new UTF8Encoding();
        Byte[] byteArray = encoding.GetBytes(dsd.DataXML);
        MemoryStream stream = new MemoryStream(byteArray);
        XmlReader reader = new XmlTextReader(stream);
        ds.ReadXml(reader);
        XDocument xd = XDocument.Parse(dsd.DataXML);
        foreach (DataTable dt in ds.Tables)
        {						
            var rs = from row in xd.Descendants(dt.TableName)
                     select row;			
 			
            int i = 0;
            foreach (var r in rs)
            {
                DataRowState state = (DataRowState)Enum.Parse(typeof(DataRowState), r.Attribute("RowState").Value);
                DataRow dr = dt.Rows[i];
                dr.AcceptChanges();
                if (state == DataRowState.Deleted)
                    dr.Delete();
                else if (state == DataRowState.Added)
                    dr.SetAdded();
                else if (state == DataRowState.Modified)
                    dr.SetModified();               
                i++;
            }
        }            
        return ds;
    }
开发者ID:RandWilliams,项目名称:SWE7903,代码行数:31,代码来源:DataSetData.cs

示例15: In

    public void In(
      [FriendlyName("Key", "The string to be used to generate the hash from.")]
      string Key,
      
      [FriendlyName("SHA1 Hash", "The SHA1 Hash generated by the Key.")]
      out string Hash
      )
    {
        if (Key != "")
          {
         UTF8Encoding ue = new UTF8Encoding();
         byte[] bytes = ue.GetBytes(Key);

         // encrypt bytes
         SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
         byte[] hashBytes = sha1.ComputeHash(bytes);

         // Convert the encrypted bytes back to a string (base 16)
         string tmpHash = "";

         for (int i = 0; i < hashBytes.Length; i++)
         {
            tmpHash += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
         }

         Hash = tmpHash.PadLeft(32, '0');
          }
          else
          {
         uScriptDebug.Log("[Generate SHA1 Hash] The Key provided was empty, returning an empty string for the SHA1 Hash.", uScriptDebug.Type.Warning);
         Hash = "";
          }
    }
开发者ID:Oxy949,项目名称:Obscended,代码行数:33,代码来源:uScriptAct_GenerateSHA1Hash.cs


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