本文整理汇总了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;
});
}
示例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;
}
示例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;
}
示例4: PosTest1
public void PosTest1()
{
String chars = "UTF8 Encoding Example";
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars);
Assert.Equal(chars.Length, byteCount);
}
示例5: PosTest2
public void PosTest2()
{
Char[] chars = new Char[] { };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 0, 0);
Assert.Equal(0, byteCount);
}
示例6: PosTest2
public void PosTest2()
{
String chars = "";
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars);
Assert.Equal(0, byteCount);
}
示例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;
}
示例8: NegTest1
public void NegTest1()
{
Char[] chars = null;
UTF8Encoding utf8 = new UTF8Encoding();
Assert.Throws<ArgumentNullException>(() =>
{
int byteCount = utf8.GetByteCount(chars, 0, 0);
});
}
示例9: PosTest1
public void PosTest1()
{
Char[] chars = new Char[] {
'\u0023',
'\u0025',
'\u03a0',
'\u03a3' };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 1, 2);
}
示例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;
}
}
示例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);
}
示例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);
});
}
示例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);
}
示例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);
});
}
示例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;
}