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. :)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...