Write a console-based program that asks a user for a business
name. Suggest a good Web address by adding "www."
to the front of the name, removing all spaces from the name,
and adding ".com" to the end of the name. For example,
a good Web address for "Acme Plumbing and Supply"
is www.AcmePlumbingandSupply.com
My question: why I can only type 1 character? If I type two letters than the program gives me an error... Also how can i remove spaces from the text user enters?
What I have done:
string userInputString;
char userInput;
string www = "www";
string com = ".com";
Console.WriteLine("Please enter your business name");
userInputString = Console.ReadLine();
userInput = Convert.ToChar(userInputString);
Console.WriteLine(www + userInput + com);
Loading
Satyapriya NayakPosted Jan 5, 2012, 12:40 AM
Try this...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string userInputString;
string userInput;
string www = "www.";
string com = ".com";
Console.WriteLine("Please enter your business name");
userInputString = Console.ReadLine();
userInput = Convert.ToString(userInputString);
Console.WriteLine(www + userInput.Replace(" ","") + com);
Console.ReadLine();
}
}
}
Thanks
AartiPosted Jan 5, 2012, 12:58 AM
userInput = Convert.ToChar(userInputString);// cant convert string to char
use this
userInput = userInputString.Trim();
Shen HengbinPosted Jan 5, 2012, 12:42 AM
userInput = Convert.ToChar(userInputString);
String cannt convert to 1 char , and you need not to convert it.
you can directly use userInputString.
Q2 : remove spaces is like
userInputString.trim()
string userInputString;
string www = "www";
string com = ".com";
Console.WriteLine("Please enter your business name");
userInputString = Console.ReadLine().Trim();
Console.WriteLine(www + userInputString + com);
Console.Read();