2 Replies - 254 Views - Last Post: 25 November 2019 - 02:28 PM Rate Topic: -----

#1 albert003   User is offline

  • D.I.C Addict

Reputation: 37
  • View blog
  • Posts: 815
  • Joined: 15-December 14

Show only first word inputted

Posted 25 November 2019 - 12:30 PM

I tried to figure it out myself and looked online and couldn't find the answer.

I know in C++ I can say
std::cout<<"What is your name?"<<std:;endl;
std::string fname;
std:;cin >> fname;

//prints first name

I tried googling under ignore white space, ignore second word inputted. How would I do that in C#?
Is This A Good Question/Topic? 0
  • +

Replies To: Show only first word inputted

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15497
  • View blog
  • Posts: 62,060
  • Joined: 12-June 08

Re: Show only first word inputted

Posted 25 November 2019 - 01:37 PM

Use string function split around a space, and take the first item in the array.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7239
  • View blog
  • Posts: 24,542
  • Joined: 05-May 12

Re: Show only first word inputted

Posted 25 November 2019 - 02:28 PM

C# doesn't have a stream extraction operator (>>) like C++ does. As to why this Anders designed the language this way, I don't know.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1