# Replace string

**URL:** <https://www.ruby-forum.com/t/replace-string/168933>\
**Category:** Rails\
**Created:** [May 27, 2009, 2:58pm UTC](https://www.ruby-forum.com/t/replace-string/168933 "2009-05-27T14:58:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dharshannew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5fc32e/32.png) [@dharshannew](https://www.ruby-forum.com/u/dharshannew)\
**Post date:** [May 27, 2009, 2:58pm UTC](https://www.ruby-forum.com/t/replace-string/168933/1 "2009-05-27T14:58:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dharshannew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5fc32e/32.png) [@dharshannew](https://www.ruby-forum.com/u/dharshannew)\
**Post date:** [May 27, 2009, 3:33pm UTC](https://www.ruby-forum.com/t/replace-string/168933/2 "2009-05-27T15:33:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dharshannew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5fc32e/32.png) [@dharshannew](https://www.ruby-forum.com/u/dharshannew)\
**Post date:** [May 27, 2009, 3:38pm UTC](https://www.ruby-forum.com/t/replace-string/168933/3 "2009-05-27T15:38:38Z")

</div>

2009/5/27 Ruby O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> 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
