Forum: Ruby on Rails replace string

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F291b17f81647310d8a4284a26c879b2?d=identicon&s=25 Ruby One (rubyone)
on 2009-05-27 14:58
hi all,



i have a string need to replace every 10th blank space of the string
with some special character.is it possible, the string does not have any
"\n", one single line.

suppose this is the string "i have a string need to replace every 10th
blank space of the string with some special character.is it possible,
the string does not have any "\n", one single line." need to place @ in
place of every 10 blank space.


thanks and regards
68814ed988eee4f21b2cd07353e5e445?d=identicon&s=25 Mk 27 (mk27)
on 2009-05-27 15:33
string = "i have a string need to replace every 10th
blank space of the string with some special character.is it possible,
the string does not have any \"\\n\", one single line."

i=0
string.each_byte { |c|
  i+=1
  string[i] = '*' if i%10 == 0
}

puts string
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-05-27 15:38
(Received via mailing list)
2009/5/27 Ruby One <rails-mailing-list@andreas-s.net>

> blank space of the string with some special character.is it possible,
> the string does not have any "\n", one single line." need to place @ in
> place of every 10 blank space.
>

What have you tried in order to achieve this?
You may not end up with the most elegant solution yourself but surely
any
programmer can work out some way of achieving this.
Post your efforts and there may be some help.

Colin
This topic is locked and can not be replied to.