C# Code Question

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 3
Reputation: knightrider2006 is an unknown quantity at this point 
Solved Threads: 0
knightrider2006 knightrider2006 is offline Offline
Newbie Poster

C# Code Question

 
0
  #1
Aug 9th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: C# Code Question

 
0
  #2
Aug 9th, 2006
I think an easy way to do this is get the index of the 4th and 5th space. then get the substring between them.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 3
Reputation: knightrider2006 is an unknown quantity at this point 
Solved Threads: 0
knightrider2006 knightrider2006 is offline Offline
Newbie Poster

Re: C# Code Question

 
0
  #3
Aug 9th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 233
Reputation: Lord Soth is an unknown quantity at this point 
Solved Threads: 4
Lord Soth's Avatar
Lord Soth Lord Soth is offline Offline
Posting Whiz in Training

Re: C# Code Question

 
0
  #4
Aug 12th, 2006
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
Best regards,
Loren Soth

Crimson K. Software _________________________________________________________________ Crimson K. Blog
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 3
Reputation: knightrider2006 is an unknown quantity at this point 
Solved Threads: 0
knightrider2006 knightrider2006 is offline Offline
Newbie Poster

Re: C# Code Question

 
0
  #5
Aug 14th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: C# Code Question

 
0
  #6
Aug 15th, 2006
yeah i like the split idea better.

string[] words = string.split(" ");
fifth word =words[4]
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC