本文整理汇总了C#中System.Text.UTF8Encoding.GetByteCount方法的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding.GetByteCount方法的具体用法?C# UTF8Encoding.GetByteCount怎么用?C# UTF8Encoding.GetByteCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UTF8Encoding
的用法示例。
在下文中一共展示了UTF8Encoding.GetByteCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PosTest1
public void PosTest1()
{
String chars = "UTF8 Encoding Example";
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars);
Assert.Equal(chars.Length, byteCount);
}
示例2: PosTest2
public void PosTest2()
{
String chars = "";
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars);
Assert.Equal(0, byteCount);
}
示例3: sendString
public void sendString(String st) {
UTF8Encoding asen = new UTF8Encoding();
lock (lock1){
s.Send(BitConverter.GetBytes(asen.GetByteCount(st)),4,SocketFlags.None);
s.Send(asen.GetBytes(st));
}
}
示例4: getByteCount
public static int getByteCount(string value)
{
int count = 0;
UTF8Encoding utf8 = new UTF8Encoding();
count = utf8.GetByteCount(value);
return count + 4;
}
示例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: TestSizeWithUKPound
public void TestSizeWithUKPound()
{
UTF8Encoding encoding = new UTF8Encoding();
int baseSize = 5;
String test = "1£";
BsonString bstr = new BsonString(test);
Assert.AreEqual(baseSize + encoding.GetByteCount(test), bstr.Size, "Size didn't count the double wide pound symbol correctly");
}
示例7: ToUTF8Bytes
public static byte[] ToUTF8Bytes(this string cultureStringMsg)
{
UTF8Encoding encoding = new UTF8Encoding();
int dataLen = encoding.GetByteCount(cultureStringMsg);
byte[] utf8bytes = new byte[dataLen];
Encoding.UTF8.GetBytes(cultureStringMsg, 0, cultureStringMsg.Length, utf8bytes, 0);
return utf8bytes;
}
示例8: NegTest1
public void NegTest1()
{
String chars = null;
UTF8Encoding utf8 = new UTF8Encoding();
Assert.Throws<ArgumentNullException>(() =>
{
int byteCount = utf8.GetByteCount(chars);
});
}
示例9: Init_ServerCommunication
public static SslStream Init_ServerCommunication(string URL, int Port)
{
UTF8Encoding encoder = new UTF8Encoding();
//
//First create the header
//
byte ver = 2;
byte opcode = 0;
ushort response = 0;
string uri = @"h";
string data = "Hiya: \"hi\"";
byte[] header = new byte[8];
header[0] = ver;
header[1] = opcode;
header[2] = BitConverter.GetBytes(response)[0];
header[3] = BitConverter.GetBytes(response)[1];
if (encoder.GetByteCount(uri) > ushort.MaxValue)
throw new Exception("The URI is too large to send");
ushort uriLength = (ushort)encoder.GetByteCount(uri);
if (encoder.GetByteCount(data) > ushort.MaxValue)
throw new Exception("The data is too large to send");
ushort dataLength = (ushort)encoder.GetByteCount(data);
header[4] = BitConverter.GetBytes(uriLength)[0];
header[5] = BitConverter.GetBytes(uriLength)[1];
header[6] = BitConverter.GetBytes(dataLength)[0];
header[7] = BitConverter.GetBytes(dataLength)[1];
TcpClient clientSocket = new TcpClient(URL, Port);
SslStream sslStream = new SslStream(clientSocket.GetStream(), false, new RemoteCertificateValidationCallback(CertificateValidationCallback));
sslStream.AuthenticateAsClient(URL);
sslStream.Write(header, 0, 8);
sslStream.Write(encoder.GetBytes(uri), 0, uriLength);
sslStream.Write(encoder.GetBytes(data), 0, dataLength);
return sslStream;
}
示例10: PosTest1
public void PosTest1()
{
Char[] chars = new Char[] {
'\u0023',
'\u0025',
'\u03a0',
'\u03a3' };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 1, 2);
}
示例11: ConvertUTF8ToBytes
protected string ConvertUTF8ToBytes(string str)
{
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(str);
Byte[] bytes = new Byte[byteCount];
utf8.GetBytes(str, 0, str.Length, bytes, 0);
return Convert.ToBase64String(bytes);
}
示例12: 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);
}
示例13: 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);
});
}
示例14: IsReaderName
/// <summary>
/// �����û���
/// </summary>
/// <param name="str">��֤���ַ���</param>
/// <returns></returns>
public static bool IsReaderName(string str)
{
UTF8Encoding encoding = new UTF8Encoding();
int byteCount = encoding.GetByteCount(str);
int strLen = str.Length;
if (strLen == byteCount)
{
return true;
}
return false;
}
示例15: IsSBC
/// <summary>
/// 全角验证
/// </summary>
/// <param name="str">验证的字符串</param>
/// <returns></returns>
public static bool IsSBC(string str)
{
UTF8Encoding encoding = new UTF8Encoding();
int byteCount = encoding.GetByteCount(str);
int strLen = str.Length;
if (byteCount == strLen * 3)
{
return true;
}
return false;
}