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


C# UTF8Encoding.GetByteCount方法代码示例

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


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

示例1: 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

示例2: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

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

        try
        {
            String chars = "UTF8 Encoding Example";

            UTF8Encoding utf8 = new UTF8Encoding();
            int byteCount = utf8.GetByteCount(chars);

            if (byteCount != chars.Length)
            {
                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:l1183479157,项目名称:coreclr,代码行数:29,代码来源:utf8encodinggetbytecount2.cs

示例3: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

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

        try
        {
            Char[] chars = new Char[] {
                            '\u0023', 
                            '\u0025', 
                            '\u03a0', 
                            '\u03a3'  };

            UTF8Encoding utf8 = new UTF8Encoding();
            int byteCount = utf8.GetByteCount(chars, 1, 2);

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:28,代码来源:utf8encodinggetbytecount1.cs

示例4: 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

示例5: PosTest2

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

示例6: 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

示例7: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;

        // Add your scenario description here
        TestLibrary.TestFramework.BeginScenario("PosTest2: Verify method GetByteCount(Char[],Int32,Int32) with null char[]");

        try
        {
            Char[] chars = new Char[] { };

            UTF8Encoding utf8 = new UTF8Encoding();
            int byteCount = utf8.GetByteCount(chars, 0, 0);

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

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:29,代码来源:utf8encodinggetbytecount1.cs

示例8: NegTest1

 public void NegTest1()
 {
     Char[] chars = null;
     UTF8Encoding utf8 = new UTF8Encoding();
     Assert.Throws<ArgumentNullException>(() =>
     {
         int byteCount = utf8.GetByteCount(chars, 0, 0);
     });
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:9,代码来源:UTF8EncodingGetByteCount1.cs

示例9: PosTest1

 public void PosTest1()
 {
     Char[] chars = new Char[] {
                     '\u0023',
                     '\u0025',
                     '\u03a0',
                     '\u03a3'  };
     UTF8Encoding utf8 = new UTF8Encoding();
     int byteCount = utf8.GetByteCount(chars, 1, 2);
 }
开发者ID:eerhardt,项目名称:corefx,代码行数:10,代码来源:UTF8EncodingGetByteCount1.cs

示例10: EnsureThreadCreated

    public bool EnsureThreadCreated(string title, string message, string thread_identifier)
    {
        try
        {
            string forum_api_key = ConfigurationManager.ConnectionStrings["DisqusForumAPI"].ConnectionString;
            string post_data = "forum_api_key=" + HttpUtility.UrlEncode(forum_api_key) +
                "&title=" + HttpUtility.UrlEncode(title) +
                "&identifier=" + HttpUtility.UrlEncode(thread_identifier);
            UTF8Encoding enc = new UTF8Encoding();

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://disqus.com/api/thread_by_identifier/");
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = enc.GetByteCount(post_data);

            using (Stream req_stream = req.GetRequestStream())
            {
                req_stream.Write(enc.GetBytes(post_data), 0, enc.GetByteCount(post_data));
            }

            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            string resp_str = "";

            // We don't really care what the response is, apart from success/fail
            // And no need to parse the JSON response, so long as it says '"succeeded": true' somewhere

            using (Stream resp_stream = resp.GetResponseStream())
            {
                using (StreamReader reader = new StreamReader(resp_stream))
                {
                    resp_str = reader.ReadToEnd();
                }
            }

            return resp_str.Contains("\"succeeded\": true");
        }
        catch
        {
            return false;
        }
    }
开发者ID:mono,项目名称:moma-tool,代码行数:41,代码来源:DisqusProxy.cs

示例11: PosTest2

        public void PosTest2()
        {
            Byte[] bytes;
            Char[] chars = new Char[] { };

            UTF8Encoding utf8 = new UTF8Encoding();

            int byteCount = utf8.GetByteCount(chars, 0, 0);
            bytes = new Byte[byteCount];
            int charsEncodedCount = utf8.GetChars(bytes, 0, 0, chars, 0);
            Assert.Equal(0, charsEncodedCount);
        }
开发者ID:eerhardt,项目名称:corefx,代码行数:12,代码来源:UTF8EncodingGetChars.cs

示例12: NegTest3

 public void NegTest3()
 {
     Char[] chars = new Char[] {
                     '\u0023',
                     '\u0025',
                     '\u03a0',
                     '\u03a3'  };
     UTF8Encoding utf8 = new UTF8Encoding();
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         int byteCount = utf8.GetByteCount(chars, 1, -2);
     });
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:13,代码来源:UTF8EncodingGetByteCount1.cs

示例13: PosTest1

        public void PosTest1()
        {
            Byte[] bytes;
            Char[] chars = new Char[] {
                            '\u0023',
                            '\u0025',
                            '\u03a0',
                            '\u03a3'  };

            UTF8Encoding utf8 = new UTF8Encoding();
            int byteCount = utf8.GetByteCount(chars, 1, 2);
            bytes = new Byte[byteCount];
            int charsEncodedCount = utf8.GetChars(bytes, 1, 2, chars, 0);
        }
开发者ID:eerhardt,项目名称:corefx,代码行数:14,代码来源:UTF8EncodingGetChars.cs

示例14: NegTest2

        public void NegTest2()
        {
            Byte[] bytes;
            Char[] chars = new Char[] {
                            '\u0023',
                            '\u0025',
                            '\u03a0',
                            '\u03a3'  };
            UTF8Encoding utf8 = new UTF8Encoding();

            int byteCount = utf8.GetByteCount(chars, 1, 2);
            bytes = null;
            Assert.Throws<ArgumentNullException>(() =>
            {
                int bytesEncodedCount = utf8.GetBytes(chars, 1, 2, bytes, 0);
            });
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:17,代码来源:UTF8EncodingGetBytes1.cs

示例15: NegTest6

    public bool NegTest6()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("NegTest6: ArgumentOutOfRangeException is not thrown when byteIndex and byteCount do not denote a valid range in chars.  ");

        try
        {
            Byte[] bytes;
            Char[] chars = new Char[] {
                            '\u0023', 
                            '\u0025', 
                            '\u03a0', 
                            '\u03a3'  };

            UTF8Encoding utf8 = new UTF8Encoding();

            int byteCount = utf8.GetByteCount(chars, 1, 2);
            bytes = new Byte[byteCount];
            int charsEncodedCount = utf8.GetChars(bytes, 2, 2, chars, 1);

            TestLibrary.TestFramework.LogError("106.1", "ArgumentOutOfRangeException is not thrown when byteIndex and byteCount do not denote a valid range in chars.");
            retVal = false;
        }
        catch (ArgumentOutOfRangeException) { }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("106.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:34,代码来源:utf8encodinggetchars.cs


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