Mega Code Archive

 
Categories / Ruby / String
 

Loop through a string with while

s = "hello"        while(s["l"])     # While the string contains the substring "l"   s["l"] = "L";   # Replace first occurrence of "l" with "L" end               # Now we have "heLLo"