From: Reid Thompson Date: 2006-07-06T06:40:56+09:00 Subject: Re: Find Position of text j3n7il jones wrote: > Im trying to recreate a function I had in Delphi for ruby, but cannot > figure out how to search for a string withn a string > > Here is the Delphi code > > function ReplaceString(str, value, replacer: String): String; > var > aPos: Integer; > rslt: String; > begin > aPos := Pos(value, str); > rslt := ''; > result := str;//in case there is nothing to replace, return orig > string > while (aPos <> 0) do begin > rslt := Copy(str, 1, aPos - 1) + replacer; > rslt := rslt + Copy(str, aPos + Length(value), Length(str)); > str := rslt; > aPos := Pos(value, str); > result := rslt; > end; > end; > > As you can see after begin, it calls a pascal function called "pos" > > which just looks for value(a string) within str (another string) and > returns a number, the position of value within str. > > Possible in ruby? > > http://www.ruby-doc.org/core/classes/String.html#M001902 may be of interest