Jump to content

Recommended Posts

Posted

Hello,

I am new to this website and trying to learn c#. i want to know the mistake in my coding because when i run the program it doesnt show me anything as an answer, the example of how it should be 

the word entered = HeLLO

answer = hEllo

public static void Program3()
        {
           
            
 
            string strUserInput;
            System.Console.WriteLine("Please enter a word or a sentence:");
            strUserInput = System.Console.ReadLine();
 
 
            if (strUserInput == "a" || strUserInput == "b" || strUserInput == "c" || strUserInput == "d" || strUserInput == "e" || strUserInput == "f" || strUserInput == "g" || strUserInput == "h" || strUserInput == "i" || strUserInput == "j" || strUserInput == "k" || strUserInput == "l" || strUserInput == "m" || strUserInput == "n" || strUserInput == "o" || strUserInput == "p" || strUserInput == "q" || strUserInput == "r" || strUserInput == "s" || strUserInput == "t" || strUserInput == "u" || strUserInput == "v" || strUserInput == "w" || strUserInput == "x" || strUserInput == "y" || strUserInput == "z")
            {
                strUserInput.ToUpper();
                System.Console.WriteLine(strUserInput.ToLower());
            }
            if (strUserInput == "A" || strUserInput == "B" || strUserInput == "C" || strUserInput == "D" || strUserInput == "E" || strUserInput == "F" || strUserInput == "G" || strUserInput == "H" || strUserInput == "I" || strUserInput == "J" || strUserInput == "K" || strUserInput == "L" || strUserInput == "M" || strUserInput == "N" || strUserInput == "O" || strUserInput == "P" || strUserInput == "Q" || strUserInput == "R" || strUserInput == "S" || strUserInput == "T" || strUserInput == "U" || strUserInput == "V" || strUserInput == "W" || strUserInput == "X" || strUserInput == "Y" || strUserInput == "Z")
            {
                strUserInput.ToLower();
                System.Console.WriteLine(strUserInput.ToUpper());
            }
                       
 
            System.Console.ReadKey();
 
        }
 
Posted (edited)

So you are flipping the case of the input text? What you are doing is pretty nonsensical.

You should instead enumerate every character of the input text. Here's an example.

string line = Console.ReadLine();
StringBuilder result = new StringBuilder();

for (int i = 0; i < line.Length; i++)
{
    if (char.IsUpper(line, i))
        result.Append(char.ToLower(line[i]));
    else if (char.IsLower(line, i))
        result.Append(char.ToUpper(line[i]));
    else
        result.Append(line[i]);
}

Console.WriteLine(result.ToString());

I haven't tested it, and wrote it right here in the browser, but it should be close to what you need.

Edited by Richard Robertson
  • Moderators
Posted

shani,

Welcome to the AutoIt forum. :)

  Quote

I am new to this website and trying to learn c#

But if you have lots of c# questions then please find a c# site to ask them - we focus on AutoIt questions here. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 10/21/2013 at 8:01 AM, Richard Robertson said:

I haven't tested it, and wrote it right here in the browser, but it should be close to what you need.

Words of wisdom.

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...