本文整理汇总了C#中System.Text.ASCIIEncoding.GetCharCount方法的典型用法代码示例。如果您正苦于以下问题:C# ASCIIEncoding.GetCharCount方法的具体用法?C# ASCIIEncoding.GetCharCount怎么用?C# ASCIIEncoding.GetCharCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.ASCIIEncoding
的用法示例。
在下文中一共展示了ASCIIEncoding.GetCharCount方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoPosTest
private void DoPosTest(ASCIIEncoding ascii, byte[] bytes, int index, int count)
{
int actualValue;
ascii = new ASCIIEncoding();
actualValue = ascii.GetCharCount(bytes, index, count);
Assert.Equal(count, actualValue);
}
示例2: base64ToASCII
/// <summary>
/// Turn Base64 encoded text into ASCII.
/// </summary>
private string base64ToASCII(string text)
{
byte[] todecode_byte = Convert.FromBase64String(text);
System.Text.Decoder decoder = new System.Text.ASCIIEncoding().GetDecoder();
int charCount = decoder.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
decoder.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
return new String(decoded_char);
}
示例3: Environment
//.........这里部分代码省略.........
case Threading.Funneled:
requiredThreadLevel = Unsafe.MPI_THREAD_FUNNELED;
break;
case Threading.Serialized:
requiredThreadLevel = Unsafe.MPI_THREAD_SERIALIZED;
break;
case Threading.Multiple:
requiredThreadLevel = Unsafe.MPI_THREAD_MULTIPLE;
break;
}
if (args == null)
{
unsafe
{
int argc = 0;
byte** argv = null;
Unsafe.MPI_Init_thread(ref argc, ref argv, requiredThreadLevel, out providedThreadLevel);
}
}
else
{
ASCIIEncoding ascii = new ASCIIEncoding();
unsafe
{
// Copy args into C-style argc/argv
int my_argc = args.Length;
byte** my_argv = stackalloc byte*[my_argc];
for (int argidx = 0; argidx < my_argc; ++argidx)
{
// Copy argument into a byte array (C-style characters)
char[] arg = args[argidx].ToCharArray();
fixed (char* argp = arg)
{
int length = ascii.GetByteCount(arg);
byte* c_arg = stackalloc byte[length];
if (length > 0)
{
ascii.GetBytes(argp, arg.Length, c_arg, length);
}
my_argv[argidx] = c_arg;
}
}
// Initialize MPI
int mpi_argc = my_argc;
byte** mpi_argv = my_argv;
Unsafe.MPI_Init_thread(ref mpi_argc, ref mpi_argv, requiredThreadLevel, out providedThreadLevel);
// \todo Copy c-style argc/argv back into args
if (mpi_argc != my_argc || mpi_argv != my_argv)
{
args = new string[mpi_argc];
for (int argidx = 0; argidx < args.Length; ++argidx)
{
// Find the end of the string
int byteCount = 0;
while (mpi_argv[argidx][byteCount] != 0)
++byteCount;
// Determine how many Unicode characters we need
int charCount = ascii.GetCharCount(mpi_argv[argidx], byteCount);
// Convert ASCII characters into unicode characters
char[] chars = new char[charCount];
fixed (char* argp = chars)
{
ascii.GetChars(mpi_argv[argidx], byteCount, argp, charCount);
}
// Create the resulting string
args[argidx] = new string(chars);
}
}
}
}
switch (providedThreadLevel)
{
case Unsafe.MPI_THREAD_SINGLE:
Environment.providedThreadLevel = Threading.Single;
break;
case Unsafe.MPI_THREAD_FUNNELED:
Environment.providedThreadLevel = Threading.Funneled;
break;
case Unsafe.MPI_THREAD_SERIALIZED:
Environment.providedThreadLevel = Threading.Serialized;
break;
case Unsafe.MPI_THREAD_MULTIPLE:
Environment.providedThreadLevel = Threading.Multiple;
break;
default:
throw new ApplicationException("MPI.NET: Underlying MPI library returned incorrect value for thread level");
}
// Setup communicators
Communicator.world = Intracommunicator.Adopt(Unsafe.MPI_COMM_WORLD);
Communicator.self = Intracommunicator.Adopt(Unsafe.MPI_COMM_SELF);
}
}
示例4: DoNegAOORTest
private void DoNegAOORTest(ASCIIEncoding ascii, byte[] bytes, int index, int count)
{
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
ascii.GetCharCount(bytes, index, count);
});
}
示例5: NegTest5
public void NegTest5()
{
ASCIIEncoding ascii = new ASCIIEncoding();
byte[] bytes = null;
Assert.Throws<ArgumentNullException>(() =>
{
ascii.GetCharCount(bytes, 0, 0);
});
}
示例6: Parse
public static Property Parse(XmlNode firstProperty, string context)
{
Property rootProperty = new Property();
rootProperty.Context = context;
rootProperty.Name = firstProperty.Attributes["name"].Value;
rootProperty.FullName = firstProperty.Attributes["fullname"].Value;
string propType = firstProperty.Attributes["type"].Value;
if (propType != "array" && propType != "object")
{
if (firstProperty.Attributes["encoding"] != null)
{
if (firstProperty.Attributes["encoding"].Value == "base64")
{
byte[] todecode_byte = Convert.FromBase64String(firstProperty.InnerText);
System.Text.Decoder decoder = new System.Text.ASCIIEncoding().GetDecoder();
int charCount = decoder.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
decoder.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
rootProperty.Value = result;
}
}
else
{
rootProperty.Value = firstProperty.InnerText;
}
rootProperty.isComplete = true;
rootProperty.Type = PropertyType.Scalar;
return rootProperty;
}
else
{
rootProperty.isComplete = false;
rootProperty.Type = (propType == "array") ? PropertyType.Array : PropertyType.Object;
if (propType == "array")
{
rootProperty.Value = "Array (" + (firstProperty.Attributes["numchildren"] != null ? firstProperty.Attributes["numchildren"].Value : "") + ")";
} else {
rootProperty.Value = "Instance of " + firstProperty.Attributes["classname"].Value;
}
if (firstProperty.Attributes["children"].Value == "0")
{
rootProperty.isComplete = true;
}
else
{
int numChildren = firstProperty.Attributes["numchildren"] != null ? Convert.ToInt32(firstProperty.Attributes["numchildren"].Value) : 0;
rootProperty.isComplete = numChildren > 0 && numChildren == firstProperty.ChildNodes.Count;
foreach (XmlNode node in firstProperty.ChildNodes)
{
if (node.Attributes["name"].Value == "CLASSNAME") continue; // this is to handle http://bugs.xdebug.org/bug_view_page.php?bug_id=00000518
rootProperty.ChildProperties.Add(Property.Parse(node, context));
}
}
}
return rootProperty;
}