# Replacing spaces

**URL:** <https://www.ruby-forum.com/t/replacing-spaces/120639>\
**Category:** Ruby\
**Created:** [November 19, 2007, 2:13pm UTC](https://www.ruby-forum.com/t/replacing-spaces/120639 "2007-11-19T14:13:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [November 19, 2007, 2:13pm UTC](https://www.ruby-forum.com/t/replacing-spaces/120639/1 "2007-11-19T14:13:42Z")

</div>

I have a long string “that looks like this”. I want to replace all  
spaces in the string with " and ".

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [November 19, 2007, 2:17pm UTC](https://www.ruby-forum.com/t/replacing-spaces/120639/2 "2007-11-19T14:17:08Z")

</div>

Alle lunedÃ¬ 19 novembre 2007, Vapor … ha scritto:

> I have a long string “that looks like this”. I want to replace all  
> spaces in the string with " and ".

“that looks like this”.gsub(" ", " and ")  
=\> that and looks and like and this

Stefano

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [November 19, 2007, 2:22pm UTC](https://www.ruby-forum.com/t/replacing-spaces/120639/3 "2007-11-19T14:22:10Z")

</div>

Stefano C. wrote:

> Alle lunedÃ¬ 19 novembre 2007, Vapor … ha scritto:
> 
> > I have a long string “that looks like this”. I want to replace all  
> > spaces in the string with " and ".
> 
> “that looks like this”.gsub(" ", " and ")  
> =\> that and looks and like and this
> 
> Stefano

thanks 🙂
