Hi!
I'm a beginner C# programmer, and our instructor has asked me to create a verification system for our web site so that a person has to complete a puzzle before they can fill out a form to submit comments on the site, etc.
What he wants us to do is to have a random sentence displayed such as "The cow jumped over the moon" or any sentence we want. I've already done this part.
But then, he wants us to make it so that the person must type in the fifth word in the sentence to complete the verification process.
My question is.. If you have a sentence like the one listed above, what code would one use to return just the fifth word in that sentence? The sentence is a string.
Hope someone can help.
From KN
knightrider2006
0
Newbie Poster
Recommended Answers
Jump to PostI think an easy way to do this is get the index of the 4th and 5th space. then get the substring between them.
Jump to PostHi,
You can use String.Split(" ") to get an array of words of your string, this way you can also know the number of words on that string. (if you plan to use multiple possible sentences)
Loren Soth
All 5 Replies
plazmo
1
Posting Whiz in Training
knightrider2006
0
Newbie Poster
Lord Soth
4
Posting Whiz in Training
knightrider2006
0
Newbie Poster
plazmo
1
Posting Whiz in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.