Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Replace x in string with y?

I'm doing a script where the user types something in, i.e.... "chocolate pies are good". For some reason, I need it to swap all the spaces with a plus sign (+).

Is there a way I can do this easily with RGSS?

For example:

"chocolate pies are good"

Would become:

"chocolate+pies+are+good".
 

poccil

Sponsor

You use the gsub method of the String class.  Example:

Code:
  string.gsub!(/\s/,"+")

See the RPG Maker XP help file for details.  Note especially the use of a regular expression, where the help file gives further details.
 

Zeriab

Sponsor

That would swap all whitespace with +'s, not just spaces.
If you just want to swap spaces you can use this code:
Code:
string.gsub!(" ", "+")

The first block can use both a string and a regular expression ^^
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top