for loops in Ruby

Reply

Join Date: Mar 2008
Posts: 31
Reputation: kinger29 is an unknown quantity at this point 
Solved Threads: 1
kinger29 kinger29 is offline Offline
Light Poster

for loops in Ruby

 
0
  #1
Oct 14th, 2008
I am trying to search through a string to find the number of occurences of a substring. I am doing this for all the strings in an array of strings. I only have figured out the while loops so far. How can I traverse through an array of strings using a for loop?
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 94
Reputation: destin is an unknown quantity at this point 
Solved Threads: 10
destin's Avatar
destin destin is offline Offline
Junior Poster in Training

Re: for loops in Ruby

 
0
  #2
Oct 27th, 2008
You don't need to use a loop if you take advantage of the API. If you take the length of the array returned "scanning" for your substring with String#scan, you will have number of occurrences of that substring.
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the Ruby Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC