本文整理汇总了C#中System.String.ToCharArray方法的典型用法代码示例。如果您正苦于以下问题:C# String.ToCharArray方法的具体用法?C# String.ToCharArray怎么用?C# String.ToCharArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.ToCharArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: parseKey
public static byte[] parseKey(String parseThis)
{
String toParse = parseThis.Trim();
byte[] toReturn = new byte[toParse.Length/2];
foreach (char thisChar in parseThis.ToCharArray())
{
if (thisChar < '0')
return null;
if (thisChar > '9' && thisChar < 'A')
throw null;
if (thisChar > 'Z' && thisChar < 'a')
throw null;
if (thisChar > 'z')
throw null;
}
int charPos = 0;
Char[] toConvert = toParse.ToCharArray();
for (int keyPos = 0; keyPos < toReturn.Length; keyPos++)
{
Char higherVal = toConvert[charPos + 0];
Char lowerVal = toConvert[charPos + 1];
toReturn[keyPos] = hexCharToValChar(lowerVal, higherVal);
charPos += 2;
}
return toReturn;
}
示例2: FilterBannedWorlds
public static FilterResult FilterBannedWorlds(List<String> bannedWorlds, String text, bool replace, bool caseSensitive) //! case sensitive
{
int count = 0;
bool[] upperCases = new bool[text.Length];
char[] charText = text.ToCharArray ();
if (!caseSensitive) //detection of the upper case to replace them at the end
{
for (int i = 0; i < charText.Length ; ++i)
{
if (char.IsUpper (charText [i]))
{
upperCases [i] = true;
}
else
{
upperCases [i] = false;
}
}
text = text.ToLower (); //lower all the text !
}
foreach (String bannedWorld in bannedWorlds) //loop on the bad worlds list
{
count += Regex.Matches(text, bannedWorld).Count; //count the negative worlds
if (replace) //replace them if asked
{
string replacedbannedWorld = ReplaceWorld (bannedWorld);
text = text.Replace (bannedWorld, replacedbannedWorld);
}
}
if (!caseSensitive) //the text is lower -> we have to put back the upper cases
{
charText = text.ToCharArray ();
for (int i = 0; i < charText.Length ; ++i)
{
if (upperCases [i])
{
charText [i] = char.ToUpper (charText [i]);
}
else
{
charText [i] = char.ToLower (charText [i]);
}
}
text = new String(charText);
}
return new FilterResult (text, count);
}
示例3: ifade_temizle
string ifade_temizle(String str)
{
string karar_metni = "";
for (int i = 0; i < str.Length; i++)
{
if (str.ToCharArray()[i] == ' ')
{ continue; }
karar_metni += str.ToCharArray()[i];
}
return degiskenleriKoy(karar_metni);
}
示例4: setConnected
public void setConnected(String s)
{
if (s.Length > 1)
{
connected = ((int)s.ToCharArray()[0]) + "/" + ((int)s.ToCharArray()[1]);
}
else
{
connected = "0/" + (int)s.ToCharArray()[0];
}
}
示例5: Crypt
public static String Crypt(String encryptText, int shift)
{
String endString = "";
int encryptStringLength = encryptText.Length;
for (int i = 0; i < encryptStringLength; i++)
{
if (encryptText.ToCharArray()[i].Equals('1'))
{
throw new ArgumentOutOfRangeException();
}
endString += CryptChar(encryptText.ToCharArray()[i], shift);
}
return endString;
}
示例6: processAnswerTextLine
// takes a line of text document as a String and stores its info
public void processAnswerTextLine(String text)
{
String ans = "";
int distractorNumber = 0;
int counter = 0;
char[] textt = text.ToCharArray();
//while (distractorNumber < 3)
//{
while (counter < text.Length)
{
if (textt[counter] != '~')
{
ans += textt[counter];
}
else
{
answerChoices[distractorNumber] = ans;
ans = "";
distractorNumber++;
}
counter++;
}
//}
}
示例7: CheckLicense
public static bool CheckLicense(String LicenseKey)
{
StringBuilder SB = new StringBuilder();
StringBuilder SB1 = new StringBuilder();
String SerialID = GetSerial();
char[] Chars = SerialID.ToString().ToCharArray();
double R1 = 0;
for (int i = 0; i < Chars.Length; i++)
{
int B = (int)Chars[i];
int E = (int)Chars[Chars.Length - i - 1];
double R = Math.Pow(B * E, 3);
R1 = R1 + R * i;
SB.Append(R1.ToString());
}
String Temp = SB.ToString();
for (int i = 0; i < LicenseKey.Length; i++)
{
char C = LicenseKey.ToCharArray()[i];
int C1 = Convert.ToInt16(C);
if ((C1 >= 48) & (C1 <= 59))
SB1.Append((int)C1 - 48);
}
if (Temp == SB1.ToString())
return true;
else return false;
}
示例8: reverseSentence
public static String reverseSentence(String sentence)
{
char[] reversedSentence = sentence.ToCharArray ();
Array.Reverse (reversedSentence);
return new string (reversedSentence);
}
示例9: FuzzyCompare
/// <summary>
/// Confronta 2 stringhe eliminando caratteri speciali \n
/// e restituendo il coefficiente di matching
/// </summary>
public static double FuzzyCompare(this String str1, String str2)
{
str1 = str1.Trim().ToLowerInvariant();
str2 = str2.Trim().ToLowerInvariant();
if (String.Compare(str1, str2, true) == 0) return 1.0;
char[] chars1 = str1.ToCharArray();
char[] chars2 = str2.ToCharArray();
int pos1 = 0;
int pos2 = 0;
int length1 = chars1.Length;
int length2 = chars2.Length;
int matchCount = 0;
bool cont = true;
while (true)
{
char c1 = '_', c2 = '/';
length1++;
do
{
length1--;
if (pos1 == chars1.Length)
{
cont = false;
break;
}
c1 = chars1[pos1++];
} while (!((c1 >= 'a' && c1 <= 'z') || (c1 >= '0' && c1 <= '9')));
length2++;
do
{
length2--;
if (pos2 == chars2.Length)
{
cont = false;
break;
}
c2 = chars2[pos2++];
} while (!((c2 >= 'a' && c2 <= 'z') || (c2 >= '0' && c2 <= '9')));
if (!cont) break;
if (c1 == c2)
{
matchCount++;
}
else
{
break;
}
}
int maxLength = Math.Max(length1, length2);
return matchCount / (double)maxLength;
}
示例10: reverse
//Convert integer to string, place in char array, reverse char array, convert to string
public String reverse(int x)
{
target = x.ToString();
char[] charArray = target.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
示例11: DrawClickText
public bool DrawClickText(int x, int y, String s,
int mosX, int mosY, bool mouseClick)
{
if (s.Length == 0) return false;
int eX = x + GetStringSpace(s.ToCharArray());
bool r = false;
if ((mosX > x) &&
(mosX < eX) &&
(mosY > y) &&
(mosY < y + (int)(36.0f * size)))
{
color = Color.Yellow;
if (mouseClick) r = true;
}
else
{
color = Color.White;
}
DrawText(x, y, s);
return r;
}
示例12: rot13
private String rot13(String stringToRotate)
{
Char[] stringAsCharArray = stringToRotate.ToCharArray();
String result = "";
foreach (Char character in stringAsCharArray)
{
// Get the int value of the character
int characterAsciiValue = (int)character;
if (characterAsciiValue >= UPPERCASE_A_ASCII_VALUE && characterAsciiValue <= UPPERCASE_Z_ASCII_VALUE)
{
// Character is a capital letter (A - Z)
characterAsciiValue -= UPPERCASE_A_ASCII_VALUE;
characterAsciiValue += N_PLACES_TO_ROTATE;
characterAsciiValue = characterAsciiValue % N_CHARACTERS_IN_ALPHABET;
characterAsciiValue += UPPERCASE_A_ASCII_VALUE;
}
if (characterAsciiValue >= LOWERCASE_A_ASCII_VALUE && characterAsciiValue <= LOWERCASE_Z_ASCII_VALUE)
{
// Character is a lowercase letter (a - z)
characterAsciiValue -= LOWERCASE_A_ASCII_VALUE;
characterAsciiValue += N_PLACES_TO_ROTATE;
characterAsciiValue = characterAsciiValue % N_CHARACTERS_IN_ALPHABET;
characterAsciiValue += LOWERCASE_A_ASCII_VALUE;
}
// cast the character ASCII value to a character and add it to result
result += (char)characterAsciiValue;
}
return result;
}
示例13: FindAnagram
public Boolean FindAnagram(String s1, String s2)
{
if (s1.Length != s2.Length)
return false;
char[] charS1 = s1.ToCharArray();
char[] charS2 = s2.ToCharArray();
int[] countS1 = new int[numberOfChar];//dictionary 256
int[] countS2 = new int[numberOfChar];
//both string characters should exist in both string with same count
for (int i = 0; i < s1.Length ; i++)
{
countS1[charS1[i]]++; // ascii value as a index
countS2[charS2[i]]++;
}
for (int i = 0; i < numberOfChar; i++)
{
if(countS1[i]!=countS2[i])
return false;
}
return true;
}
示例14: AddNewDictItem
protected override EnumError AddNewDictItem(String pword, int pCnt)
{
char[] chars = pword.ToCharArray();
String prefix = "";
foreach (char ch in chars)
{
prefix += ch;
if (dac.ContainsKey(prefix))
{
WordItem wi = new WordItem(pword,pCnt);
ListOfWordItemSorted lowi = dac[prefix];
lowi.Add(wi, null);
//В списке TopN слов всегда храним не более topNWords слов.
if (lowi.Count > base.topNWords)
{
lowi.RemoveAt(base.topNWords);
}
}
else
{
ListOfWordItemSorted lowi = new ListOfWordItemSorted();
lowi.Capacity = base.topNWords+1;
WordItem wi = new WordItem(pword,pCnt);
lowi.Add(wi, null);
dac.Add(prefix, lowi);
}
}
return EnumError.NoError;
}
示例15: StringWidth
public int StringWidth(String str)
{
int len = str.Length;
char[] data = new char[len];
Array.Copy(str.ToCharArray(), 0, data, 0,len);
return CharsWidth(data, 0, len);
}