C# Lesson 9

Matt Bauer 2/3/2020

How to make Strings do your bidding.

In this lesson we are going to learn how to iterate over a string and ignore case when comparing them.


using System;

namespace Lesson9
{
    class StringManipulation
    {
        static void Main(string[] args)
        {
            string alphabet = "abcd";
            for (int index = 0; index < alphabet.Length; index++)
            {
                //string letter = alphabet[index]; // Doesn't work
                char letter = alphabet[index];
                Console.WriteLine($"char at index {index}: {letter}");
            }

            //Index out of bounds rant
            string reverse = "";
            for (int index = alphabet.Length - 1; index >= 0; index--)
            {
                //string letter = alphabet[index]; // Doesn't work
                char letter = alphabet[index];
                Console.WriteLine($"char at index {index}: {letter}");
                reverse += letter;
            }

            Console.WriteLine(reverse);


            // using ToLower and ToUpper for string compaire
            string userInput;

            do
            {
                Console.Write("Type 'exit' to quit: ");
                userInput = Console.ReadLine();

            } while (userInput.ToUpper() != "exit");


        }
    }
}


/*
* TASK:
*   Make a Program that takes a string from the user the displays if the string is a palindrom or not.
*   A palindrome is a word, phrase, number or sequence of words that reads the same backward as forward.
*   Spaces between words is allowed and must be dealt with by the program. 
*   
*   Assume any other punctuation will not be entered by the user. Example: ',".? ect... 
*   
*   Example Output:
*       Enter a string:
*       Level
*       level is a palindrome!
*   
*   
*   Example Output:
*       Enter a string:
*       Blue
*       blue is not a palindrome!
*   
*   
*   Example Output:
*       Enter a string:
*       My GYm
*       my gym is a palindrome!
*   
*   
*   
*   NOTE: You will have to handle both uppercase and lowercase letters.
*/

using System;

namespace Lesson9Task
{
    class StringManipulationTask
    {
        static void Main(string[] args)
        {
        }
    }
}