本文整理汇总了C#中Char类的典型用法代码示例。如果您正苦于以下问题:C# Char类的具体用法?C# Char怎么用?C# Char使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Char类属于命名空间,在下文中一共展示了Char类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: Main
static void Main()
{
Console.Write("Enter word: ");
string word = Console.ReadLine();
char[] letters = new Char[52];
for (int i = 0; i < 52; i++)
{
if (i < 26)
{
letters[i] = (char)(i + 65);
}
else
{
letters[i] = (char)(i + 71);
}
}
for (int i = 0; i < word.Length; i++)
{
for (int j = 0; j < letters.Length; j++)
{
if (word[i] == letters[j])
{
Console.WriteLine("{0} -> {1}", letters[j], j);
}
}
}
}
示例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: SetCompare
public void SetCompare(Char c)
{
if (c == 'Y')
_CompareDel = CompareToY;
else
_CompareDel = CompareToX;
}
示例5: ArraysFullyIncluded
public static SqlBoolean ArraysFullyIncluded(String AArray, String ASubArray, Char ASeparator)
{
//String
// LArray = (AArray.IsNull ? null : AArray.Value),
// LSubArray = (ASubArray.IsNull ? null : ASubArray.Value);
if (String.IsNullOrEmpty(ASubArray) || ASubArray.Equals(ASeparator))
return true;
if (String.IsNullOrEmpty(AArray) || AArray.Equals(ASeparator))
return false;
if (AArray.Equals("*"))
return new SqlBoolean(true);
if (ASubArray.Equals("*"))
return new SqlBoolean(false);
AArray = ASeparator + AArray + ASeparator;
foreach(String LItem in ASubArray.Split(new char[]{ASeparator}, StringSplitOptions.RemoveEmptyEntries))
{
if(AArray.IndexOf(ASeparator + LItem + ASeparator) == -1)
return false;
}
return true;
}
示例6: VerifyCharTryParse
public static bool VerifyCharTryParse(string value, Char expectedResult, bool expectedReturn)
{
Char result;
if (verbose)
{
TestLibrary.Logging.WriteLine("Test: Char.TryParse, Value = '{0}', Expected Result, {1}, Expected Return = {2}",
value, expectedResult, expectedReturn);
}
try
{
bool returnValue = Char.TryParse(value, out result);
if (returnValue != expectedReturn)
{
TestLibrary.Logging.WriteLine("FAILURE: Value = '{0}', Expected Return: {1}, Actual Return: {2}", value, expectedReturn, returnValue);
return false;
}
if (result != expectedResult)
{
TestLibrary.Logging.WriteLine("FAILURE: Value = '{0}', Expected Result: {1}, Actual Result: {2}", value, expectedResult, result);
return false;
}
return true;
}
catch (Exception ex)
{
TestLibrary.Logging.WriteLine("FAILURE: Unexpected Exception, Value = '{0}', Exception: {1}", value, ex);
return false;
}
}
示例7: GetMessageFromWeb
public static string GetMessageFromWeb(string strURL)
{
System.Text.StringBuilder sbuBuilder;
// Creates an HttpWebRequest with the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
// Gets the stream associated with the response.
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader(receiveStream, encode);
sbuBuilder = new System.Text.StringBuilder();
Char[] read = new Char[READ_CHUNK_SIZE];
// Reads 256 characters at a time.
int count = readStream.Read(read, 0, READ_CHUNK_SIZE);
while (count > 0)
{
sbuBuilder.Append(read);
if (count < READ_CHUNK_SIZE)
{
sbuBuilder.Remove(sbuBuilder.Length - (READ_CHUNK_SIZE - count), READ_CHUNK_SIZE - count);
}
count = readStream.Read(read, 0, READ_CHUNK_SIZE);
}
myHttpWebResponse.Close();
readStream.Close();
return sbuBuilder.ToString();
}
示例8: IntlStrings
public virtual bool runTest
()
{
System.Console.Error.WriteLine( "String.EndsWith: Co1150EW runTest starting..." );
int nErrorBits = 0;
System.String swrString2 = null;
swrString2 = "nOpqRs";
if ( swrString2.EndsWith( "qRs" ) != true )
nErrorBits = nErrorBits | 0x1;
if ( swrString2.EndsWith( "qrs" ) != false )
nErrorBits = nErrorBits | 0x2;
if ( swrString2.EndsWith( "nOp" ) != false )
nErrorBits = nErrorBits | 0x4;
Char[] swrString3 = new Char[8];
IntlStrings intl = new IntlStrings();
swrString2 = intl.GetString(10, true, true);
swrString2.CopyTo(2, swrString3, 0, swrString2.Length - 2);
String swrString4 = new String(swrString3);
if(swrString2.EndsWith(swrString4) != true) {
nErrorBits = nErrorBits | 0x1;
}
System.Console.Error.WriteLine( nErrorBits );
if (nErrorBits == 0)
{
return true;
}
else
{
return false;
}
}
示例9: ShortestDistance
Int32 ShortestDistance(Char[,] map)
{
Int32 i, j, sh, shi, shj, n = map.GetLength(0), m = map.GetLength(1);
Int32[,] dist = new Int32[n, m];
for (i = 0; i < n; ++i) {
for (j = 0; j < m; ++j) {
dist[i, j] = -1;
}
}
dist[0, 0] = 0;
Queue<Int32> qu = new Queue<Int32>();
qu.Enqueue(0);
qu.Enqueue(0);
while (qu.Count != 0) {
i = qu.Dequeue();
j = qu.Dequeue();
if (map[i, j] == 'x') {
return dist[i, j];
}
for (sh = 0; sh < 4; ++sh) {
shi = i + shift[sh, 0];
shj = j + shift[sh, 1];
if (shi >= 0 && shj >= 0 && shi < n && shj < m && map[shi, shj] != '#' && dist[shi, shj] < 0) {
dist[shi, shj] = dist[i, j] + 1;
qu.Enqueue(shi);
qu.Enqueue(shj);
}
}
}
return -1;
}
示例10: PosTest2
public void PosTest2()
{
Char[] chars = new Char[] { };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 0, 0);
Assert.Equal(0, byteCount);
}
示例11: Main
static void Main()
{
Console.Write("Enter an unsigned integer number: ");
uint number = uint.Parse(Console.ReadLine());
Console.Write("Enter first bit position: ");
int p = int.Parse(Console.ReadLine());
Console.Write("Enter second bit position: ");
int q = int.Parse(Console.ReadLine());
Console.Write("Enter number of bits to swap: ");
int k = int.Parse(Console.ReadLine());
if (Math.Abs(q - p) < k)
{
Console.WriteLine("Bits to swap are overlapping! You stupid whore!");
return;
}
string bitStr = Convert.ToString(number, 2).PadLeft(32, '0');
char[] newStr = new Char[32];
newStr = bitStr.ToCharArray();
for (int i = 0; i < k; i++)
{
newStr[31 - p - i] = bitStr[31 - q - i];
newStr[31 - q - i] = bitStr[31 - p - i];
}
string new_bitStr = new String(newStr);
uint new_num = Convert.ToUInt32(new_bitStr, 2);
Console.WriteLine("The old number was: {0}", bitStr);
Console.WriteLine("The new number is: {0}", new_bitStr);
}
示例12: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//make call to external url and display results
WebResponse result = null;
string output = "";
WebRequest req = WebRequest.Create(ServletCallUrl);
result = req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader sr = new StreamReader(ReceiveStream, encode);
Char[] read = new Char[256];
int count = sr.Read(read, 0, read.Length);
while (count > 0)
{
String str = new String(read, 0, count);
output += str;
count = sr.Read(read, 0, read.Length);
}
if (result != null)
{
result.Close();
}
Response.Write(output);
}
示例13: PosTest1
public bool PosTest1()
{
bool retVal = true;
Char[] chars = new Char[] { } ;
UnicodeEncoding uEncoding = new UnicodeEncoding();
int expectedValue = 0;
int actualValue;
TestLibrary.TestFramework.BeginScenario("PosTest1:Invoke the method with a empty char array.");
try
{
actualValue = uEncoding.GetByteCount(chars,0,0);
if (expectedValue != actualValue)
{
TestLibrary.TestFramework.LogError("001", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpected exception:" + e);
retVal = false;
}
return retVal;
}
示例14: VerifyInvalidReadValue
private bool VerifyInvalidReadValue(int iBufferSize, int iIndex, int iCount, Type exceptionType)
{
bool bPassed = false;
Char[] buffer = new Char[iBufferSize];
ReloadSource();
DataReader.PositionOnElement(ST_TEST_NAME);
DataReader.Read();
if (!DataReader.CanReadValueChunk)
{
try
{
DataReader.ReadValueChunk(buffer, 0, 5);
return bPassed;
}
catch (NotSupportedException)
{
return true;
}
}
try
{
DataReader.ReadValueChunk(buffer, iIndex, iCount);
}
catch (Exception e)
{
CError.WriteLine("Actual exception:{0}", e.GetType().ToString());
CError.WriteLine("Expected exception:{0}", exceptionType.ToString());
bPassed = (e.GetType().ToString() == exceptionType.ToString());
}
return bPassed;
}
示例15: WcsToMbsConverter
private static Int32 WcsToMbsConverter(int codePage, IntPtr inStr, Int32 inLen, IntPtr outBuffer, Int32 outSize)
{
Char[] inBuffer = new Char[inLen];
Marshal.Copy(inStr, inBuffer, 0, inBuffer.Length);
Encoding encoder;
if(codePage==936)
{
encoder = Encoding.UTF8;
}
else
{
encoder = Encoding.GetEncoding(codePage);
}
if (outBuffer == IntPtr.Zero) //query out length
{
return encoder.GetByteCount(inBuffer);
}
else
{
Byte[] outData = encoder.GetBytes(inBuffer);
if (outData.Length > outSize) //out buffer too small
return -1;
Marshal.Copy(outData, 0, outBuffer, outData.Length);
return outData.Length;
}
}