當前位置: 首頁>>代碼示例>>C#>>正文


C# String.ToCharArray方法代碼示例

本文整理匯總了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;
        }
開發者ID:randomdude,項目名稱:Lavalamp,代碼行數:29,代碼來源:key.cs

示例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);
		}
開發者ID:nburon,項目名稱:Euromoney.RecruitmentTest,代碼行數:57,代碼來源:Filter.cs

示例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);
 }
開發者ID:zeyd17,項目名稱:Algoritma_Egitim_Prog,代碼行數:11,代碼來源:Karar.cs

示例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];
     }
 }
開發者ID:ChristopheTdn,項目名稱:FSF-LAUNCHER-ARMA3,代碼行數:11,代碼來源:CallArma3Server.cs

示例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;
 }
開發者ID:xjMavericKjx,項目名稱:Encrypt,代碼行數:14,代碼來源:Caesar.cs

示例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++;
                }

            //}
        }
開發者ID:sarangjo,項目名稱:IonoWumpus,代碼行數:27,代碼來源:Question.cs

示例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;
 }
開發者ID:Bia10,項目名稱:clrn,代碼行數:27,代碼來源:Defender.cs

示例8: reverseSentence

        public static String reverseSentence(String sentence)
        {
            char[] reversedSentence = sentence.ToCharArray ();
            Array.Reverse (reversedSentence);

            return new string (reversedSentence);
        }
開發者ID:lizaamini,項目名稱:CSharpExercises,代碼行數:7,代碼來源:Exercise8A.cs

示例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;
        }
開發者ID:mdnmdn,項目名稱:salato-dana,代碼行數:64,代碼來源:StringExtenders.cs

示例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);
 }
開發者ID:dompenn2010,項目名稱:Project-Euler,代碼行數:8,代碼來源:PalindromeFinder.cs

示例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;
        }
開發者ID:o3a,項目名稱:ZombieSmashersXNA4,代碼行數:25,代碼來源:Text.cs

示例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;
        }
開發者ID:paddymoran,項目名稱:IN710morapd1,代碼行數:34,代碼來源:Encryptors.cs

示例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;
        }
開發者ID:anuprao152,項目名稱:GitHub-WebApp,代碼行數:26,代碼來源:Anagram.cs

示例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;
        }
開發者ID:mayatforest,項目名稱:AutoComplete,代碼行數:31,代碼來源:SimplePrefixBuilder.cs

示例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);
 }
開發者ID:Orvid,項目名稱:Cosmos,代碼行數:7,代碼來源:FontMetrics.cs


注:本文中的System.String.ToCharArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。