FAQ: Working with Text - Review

This extra home work does not make sense. Asking us to make a program with insufficient knowledge at this level. Simply they could have asked and mentioned use fix string value and manually change each and every part of the string and concatenate everything at the end.

Not happy

Thanks

This was my total noob solution, not using system.Text or system.Linq as I didn’t know about those. I did lookup the random function, otherwise just figured it out.

        string text = "The quick brown fox jumped over the lazy dog";
        int StrLength = text.Length;
        int halfStrLength = (text.Length / 2); // change the case of half of the characters

        for (int i = 1; i <= halfStrLength; i++)  // convert half the characters
        {
            int position = GetRandomNumber(1, text.Length); // get a random position between 1 and the end of the string
            char letter = text[position]; // get the letter at this position
            if (Char.IsLower(letter)) // if the letter is lowercase
            {
                string letterStr = letter.ToString(); // convert it to a string
                string upperLetter = letterStr.ToUpper(); // convert it to uppercase
                string firstPart = text.Substring(0, position); // get the first part of the word
                string lastPart = text.Substring(position + 1, StrLength - position - 1); // we have to add one to account for the upperLetter
                text = firstPart + upperLetter + lastPart; // reconstruct the string
            }
            else // otherwise it's a cap or space so we won't count this interaction
            {
                i--;
            }

        }
        Console.WriteLine(text);
        Console.ReadLine();

I am a complete newby when it comes to C# and just started using CodeAcademy. What youre saying is completely valid. When it said to create a Random Case Generator; i was like huh??? Even looking at the link showing what it was i was still like HUH!!! Idk i did the java script course on Khan Academy and I learned alot and enjoyed doing it. The “extra homework” on this course is completely confusing and theres 0 direction and the expectations arent possible considering whats been taught. Im low key frustrated -_-

1 Like

hey,
I think without some prior coding experience it’s can be difficult to achieve, cause it’s cannot be made
with just what the tutorial taught at this moment.
But with some will, you can do almost anything.

If you want to try it, you can play with intervalMax and forLongMax variables to change the max interval between every modification and for how much characters every time.

using System;

namespace Review
{
  class Program
  {
    static void Main(string[] args)
    {
      string str = "Nous offrons des solutions d'assurance voyage personnalisées pour tous les types de voyageurs. Vous êtes un snowbird, un étudiant qui voyage à l'étranger ou un visiteur au Canada ou encore vous prévoyez des vacances en famille? Croix Bleue peut répondre à vos besoins.";   

      string newString = "";

      int intervalMax = 10;  
      int forLongMax = 2;

      int tmp = 0;

      do{
        // Letter Selection
        int randomLetterNum = new Random().Next(tmp, (tmp + intervalMax) > str.Length ? str.Length : (tmp + intervalMax));

        // Number of Chars to be uppercased
        int forLong = new Random().Next(1, (str.Length - randomLetterNum) > forLongMax ? forLongMax : (str.Length - randomLetterNum));

        // Push non changed Chars to new string
        newString = newString + str.Substring(tmp, (randomLetterNum - tmp ));

        // Push non changed Chars to new string
        newString = newString + str.Substring(randomLetterNum, forLong).ToUpper();

        // Tmp update 
        tmp = randomLetterNum + forLong;        
      } while(tmp < str.Length);

      Console.WriteLine(newString);
    }
  }
}

That was to difficult

namespace codeacdemy1
{
    class Program
    {
        static void Main(string[] args)
        {
            string randomText = "Time for some practice! Use the code editor ";
            var random = new Random();
            var randomCase = new List<string> { };

            char[] charArray = randomText.ToCharArray();

            foreach (char letter in charArray)
            {
                int number = random.Next(0, 2);
                if (number == 1)
                {
                    randomCase.Add(letter.ToString().ToLower());
                }
                else
                {
                    randomCase.Add(letter.ToString().ToUpper());
                }
            }
            Console.WriteLine(String.Join("",randomCase));
        }
    }
}

hi
why did you take the range for Next only 0-2? and why not the full length of the string?