当前位置: 首页>>代码示例>>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;未经允许,请勿转载。