shani Posted October 20, 2013 Posted October 20, 2013 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(); }
Richard Robertson Posted October 21, 2013 Posted October 21, 2013 (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 October 21, 2013 by Richard Robertson
Moderators Melba23 Posted October 21, 2013 Moderators Posted October 21, 2013 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
DatMCEyeBall Posted October 22, 2013 Posted October 22, 2013 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now