944,129 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 3929
  • C# RSS
Aug 9th, 2006
0

C# Code Question

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
knightrider2006 is offline Offline
3 posts
since Aug 2006
Aug 9th, 2006
0

Re: C# Code Question

I think an easy way to do this is get the index of the 4th and 5th space. then get the substring between them.
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005
Aug 9th, 2006
0

Re: C# Code Question

Hmmm..Not really sure how that will work exactly.. An example might be useful to look at so I can see what's happening, then try to take that and translate it for my own project. All I want to get is that fifth word
Reputation Points: 10
Solved Threads: 0
Newbie Poster
knightrider2006 is offline Offline
3 posts
since Aug 2006
Aug 12th, 2006
0

Re: C# Code Question

Hi,

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
Reputation Points: 28
Solved Threads: 4
Posting Whiz in Training
Lord Soth is offline Offline
233 posts
since Mar 2006
Aug 14th, 2006
0

Re: C# Code Question

Hey!
Well, I did the string.split to create an array of words. Now how do I take that array of words and get the fourth word out of it and return it as a string?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
knightrider2006 is offline Offline
3 posts
since Aug 2006
Aug 15th, 2006
0

Re: C# Code Question

yeah i like the split idea better.

string[] words = string.split(" ");
fifth word =words[4]
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Serialization to XML + Encryption
Next Thread in C# Forum Timeline: Strings help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC