本文整理汇总了C#中System.Text.UnicodeEncoding.GetCharCount方法的典型用法代码示例。如果您正苦于以下问题:C# UnicodeEncoding.GetCharCount方法的具体用法?C# UnicodeEncoding.GetCharCount怎么用?C# UnicodeEncoding.GetCharCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UnicodeEncoding
的用法示例。
在下文中一共展示了UnicodeEncoding.GetCharCount方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PosTest4
public void PosTest4()
{
Char[] chars = GetCharArray(10);
Byte[] bytes = new Byte[20];
UnicodeEncoding uEncoding = new UnicodeEncoding();
int byteCount = uEncoding.GetBytes(chars, 0, 10, bytes, 0);
int actualValue;
actualValue = uEncoding.GetCharCount(bytes, 20, 0);
Assert.Equal(0, actualValue);
}
示例2: NegTest1
public void NegTest1()
{
Char[] chars = GetCharArray(10);
Byte[] bytes = new Byte[20];
UnicodeEncoding uEncoding = new UnicodeEncoding();
int byteCount = uEncoding.GetBytes(chars, 0, 10, bytes, 0);
int actualValue;
Assert.Throws<ArgumentNullException>(() =>
{
actualValue = uEncoding.GetCharCount(null, 0, 0);
});
}
示例3: SerializeObjectToXML
//public static string SerializeObjectToXML(T obj)
public static string SerializeObjectToXML(Object obj)
{
try
{
//string xmlString = null;
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xs = new XmlSerializer(obj.GetType());
string s = string.Empty;
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
SoapFormatter xsoap = new SoapFormatter();
xsoap.Serialize(memoryStream, obj);
//xmlString = UTF8ByteArrayToString(memoryStream.ToArray());
UnicodeEncoding encoding = new UnicodeEncoding();
byte[] bytes = memoryStream.ToArray();
char[] chars = new char[encoding.GetCharCount(bytes, 0, (int)memoryStream.Length)];
return new string(chars);
}
catch (Exception ex)
{
ex.GetType();
return string.Empty;
}
}
示例4: UsingMemoryStream
private void UsingMemoryStream()
{
System.Threading.Thread.Sleep(5000);
Console.WriteLine("Memory Stream Example");
int count;
byte[] byteArray;
char[] charArray;
UnicodeEncoding uniEncoding = new UnicodeEncoding();
byte[] firstString = uniEncoding.GetBytes("Invalid file path character are: ");
byte[] secondString = uniEncoding.GetBytes(Path.GetInvalidFileNameChars());
using (MemoryStream memStream = new MemoryStream(100))
{
memStream.Write(firstString, 0, firstString.Length);
count = 0;
while(count < secondString.Length)
{
memStream.WriteByte(secondString[count++]);
}
Console.WriteLine("Capacity = {0}, Length = {1}, Position = {2}",
memStream.Capacity,
memStream.Length,
memStream.Position);
memStream.Seek(0, SeekOrigin.Begin);
byteArray = new byte[memStream.Length];
count = memStream.Read(byteArray, 0, 20);
while(count<memStream.Length)
{
byteArray[count++] = Convert.ToByte(memStream.ReadByte());
}
charArray = new char[uniEncoding.GetCharCount(byteArray,0,count)];
uniEncoding.GetDecoder().GetChars(byteArray, 0, count, charArray, 0);
Console.WriteLine(charArray);
}
}
示例5: ZeroLengthArrays
public void ZeroLengthArrays ()
{
UnicodeEncoding encoding = new UnicodeEncoding ();
encoding.GetCharCount (new byte [0]);
encoding.GetChars (new byte [0]);
encoding.GetCharCount (new byte [0], 0, 0);
encoding.GetChars (new byte [0], 0, 0);
encoding.GetChars (new byte [0], 0, 0, new char [0], 0);
encoding.GetByteCount (new char [0]);
encoding.GetBytes (new char [0]);
encoding.GetByteCount (new char [0], 0, 0);
encoding.GetBytes (new char [0], 0, 0);
encoding.GetBytes (new char [0], 0, 0, new byte [0], 0);
encoding.GetByteCount ("");
encoding.GetBytes ("");
}
示例6: TestEncodingGetCharCount
public void TestEncodingGetCharCount ()
{
byte[] b = new byte[] {255, 254, 115, 0, 104, 0, 105, 0};
UnicodeEncoding encoding = new UnicodeEncoding ();
Assert.AreEqual (3, encoding.GetCharCount (b, 2, b.Length - 2),
"GetCharCount #1");
}
示例7: Send
public bool Send(string mail)
{
try
{
UnicodeEncoding encoding = new UnicodeEncoding();
string data_string = string.Format("{0}:{1}:{2}", Process.GetCurrentProcess().Id, 3, mail);
byte[] data_bytes = encoding.GetBytes(data_string);
int byteCount = data_bytes.Length;
if (byteCount > MAX_MESSAGE_SIZE)
{
Console.WriteLine(String.Format(
"message size {0} bytes but is limited to {1} bytes, will be truncated",
byteCount, MAX_MESSAGE_SIZE));
byteCount = MAX_MESSAGE_SIZE;
}
ensureMailSlot();
mailSlot.Write(data_bytes, 0, byteCount);
mailSlot.Flush();
Console.WriteLine("sending " + data_string.Substring(0, encoding.GetCharCount(data_bytes, 0, byteCount)));
}
catch (IOException ioe)
{
this.Close();
Console.WriteLine(String.Format("{0} Exception caught.", ioe));
return false;
}
return true;
}