Beispiel #1
0
        static void Main(string[] args)
        {
            int countklinkers = 0;

            Char[] klinkers = new Char[] { 'a', 'e', 'i', 'o', 'u' };
            string antwoord2;

            Console.WriteLine("Geef een tekst: ");
            string antwoord = Console.ReadLine();

            for (int i = 0; i < antwoord.Length; i++)
            {
                if (klinkers.Contains(antwoord[i]))
                {
                    countklinkers++;
                }
            }

            Console.WriteLine($"Deze tekst heeft {countklinkers} klinkers");
            Console.Write("De tekst wordt vertaald: ");
            for (int i = 0; i < antwoord.Length; i++)
            {
                Console.Write(antwoord2 = Convert.ToString(Convert.ToChar(antwoord[i] + 1)));
            }

            Console.ReadLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            char[] vowels = new Char[] { 'a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y' };
            Console.WriteLine("skriv en sträng: ");
            var input        = Console.ReadLine();
            var output       = new List <char>();
            int remowedcount = 0;

            for (int i = 0; i < input.Length; i++)
            {
                var currentCharacter    = input[i];
                var normalizedCharacter = char.ToLower(currentCharacter);

                if (vowels.Contains(normalizedCharacter) == false)
                {
                    output.Add(currentCharacter);
                }
                else
                {
                    remowedcount++;
                }
            }
            var resultingString = new string(output.ToArray());

            Console.WriteLine($"Din sträng utan vokaler: {resultingString}, vi tog bort: {remowedcount}");
        }
Beispiel #3
0
        public static int ToArabic(String roman)
        {
            Char[] sanityArray = new Char[] { 'I', 'V', 'X', 'L', 'C', 'D', 'M' };

            foreach (char i in roman)
            {
                if (sanityArray.Contains(i))
                {
                    continue;
                }
                else
                {
                    throw new FormatException();
                }
            }
            return(recArabic(roman));
        }
    public static String UnQuote(String AValue, Char[] AQuotes)
    {
        if (String.IsNullOrEmpty(AValue) || AQuotes == null || AQuotes.Length == 0) return AValue;
        Char LQuote = AValue[0];

        if (!AQuotes.Contains(LQuote))
          return AValue;
        Char RQuote = InternalGetRightQuote(LQuote);
        return AValue.Substring(1, AValue.Length - 2).Replace(new string(RQuote, 2), RQuote.ToString());
    }
    public static String RemoveCharacters(String AValue, Char[] AChars)
    {
        StringBuilder LResult = new StringBuilder(AValue.Length);

        for (int i = 0; i < AValue.Length; i++)
          if (!AChars.Contains(AValue[i]))
        LResult.Append(AValue[i]);

        //for (int i = LValue.Length - 1; i >= 0; i--)
        //  if (LChars.Contains(LValue[i]))
        //    LValue = LValue.Remove(i, 1);

        if (LResult.Length < AValue.Length)
          return LResult.ToString();
        else
          return AValue;
    }
 public static Char InternalGetRightQuote(Char ALeftQuote, Char[] AAllowedQuotes)
 {
     if (AAllowedQuotes.Contains(ALeftQuote))
       return InternalGetRightQuote(ALeftQuote);
     return (char)0;
 }
        private String RenameVariables(String input)
        {
            Char[] varNameEndChars = new Char[] { ')', '=', ';' };

            List <String> varNames;

            try
            {
                varNames = GetVariablesNames(input);
            }
            catch (InvalidCodeException ex)
            {
                input = !String.IsNullOrWhiteSpace(ex.Message)
                    ? $"{ERROR_INVALID_CODE}: {ex.Message}"
                    : ERROR_INVALID_CODE;

                return(input);
            }

            String output = "";
            Dictionary <String, String> newNames = new Dictionary <String, String>();
            bool   str      = false;
            String prevWord = "";

            foreach (var ch in input)
            {
                if (ch == '"')
                {
                    str      = !str;
                    prevWord = "";
                    output  += ch;
                    continue;
                }

                if (str)
                {
                    prevWord += ch;
                    output   += ch;
                    continue;
                }

                if (Char.IsWhiteSpace(ch) || varNameEndChars.Contains(ch))
                {
                    if (varNames.Contains(prevWord))
                    {
                        if (!newNames.TryGetValue(prevWord, out String newName))
                        {
                            newName = $"v{newNames.Count}";
                            newNames.Add(prevWord, newName);
                        }

                        output  = output.Remove(output.Length - prevWord.Length, prevWord.Length);
                        output += newName;

                        output += ch;

                        prevWord = "";
                        continue;
                    }

                    prevWord = "";
                }
                else
                {
                    prevWord += ch;
                }

                output += ch;
            }

            //foreach (var varName in varNames)
            //{
            //    String newName = $"v{++prevIndex}";

            //    input = Regex.Replace(input, $@"({varName})", $" {newName}");
            //}

            return(output);
        }
Beispiel #8
0
    //获取内容
    // 获取最大长度
    // 将字符串分割为单个字符
    // 一个一个的假如
    // 假如遇到、n重新计数
    // 假如超出 假如、n
    public string SetComtentFit(Text mText, string content, float maxWidth, bool isNewLine = true)
    {
        //切开字段
        //        string[] contents = content.Split(s, StringSplitOptions.None);

        Char[]        conChars = content.ToCharArray();
        StringBuilder sb       = new StringBuilder();
        Font          myFont   = mText.font;
        CharacterInfo characterInfo;

        myFont.RequestCharactersInTexture("郑伟博Demo", mText.fontSize, mText.fontStyle);
        myFont.GetCharacterInfo('郑', out characterInfo, mText.fontSize);
        float widthDemo = characterInfo.advance;

        myFont.RequestCharactersInTexture("1234567890", mText.fontSize, mText.fontStyle);
        myFont.GetCharacterInfo('1', out characterInfo, mText.fontSize);
        float widthNumberDemo = characterInfo.advance;

        Char[] numbers = new Char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

        myFont.RequestCharactersInTexture(content, mText.fontSize, mText.fontStyle);
        float width = 0;
        char  mChar = ' ';

        for (int i = 0; i < conChars.Length; i++)
        {
            if (conChars[i] == '\\' && i < conChars.Length - 1)
            {
                isJump = true;
            }
            else if ((isJump && conChars[i] == 'n') || conChars[i] == '\n')
            {
                width  = 0;
                isJump = false;
                mChar  = '\n';
            }
            else if ((isJump && conChars[i] == 't') || conChars[i] == '\t')
            {
                width += widthDemo;
                isJump = false;
                mChar  = '\t';
            }
            else
            {
                if (numbers.Contains(conChars[i]))
                {
                    width += widthNumberDemo;
                }
                else
                {
                    myFont.GetCharacterInfo(conChars[i], out characterInfo, mText.fontSize);
                    width += characterInfo.advance;
                }
                if (width >= maxWidth - widthDemo / 2 && isNewLine == true)
                {
                    sb.Append("\n");
                    width = 0;
                }
                mChar  = conChars[i];
                isJump = false;
            }
            if (!isJump)
            {
                sb.Append(mChar);
            }
        }
        return(sb.ToString());
    }