Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Find & Replace in Ruby

For general discussion related FlowStone

Find & Replace in Ruby

Postby Wassaka » Wed Sep 28, 2016 10:56 pm

Hi!! First, I don't know anything about Ruby.. But i am trying to do "Find/Search and Replace" but searching into a word. For example: "Hello word", "e" will be replaced by "3". So, "H3llo word". Is this possible?? Thanks!! And sorry about my bad english :(
Wassaka
 
Posts: 85
Joined: Wed Dec 30, 2015 3:41 am

Re: Find & Replace in Ruby

Postby tulamide » Thu Sep 29, 2016 12:05 pm

The string class has the methods :sub and :gsub, which replace ("substitute") based on following logic:

Code: Select all
mystring = "Hello World".sub("e", "3") # results in "H3llo world"
mystring = "Hello there".sub("e", "3") # results in "H3llo there"


Code: Select all
mystring = "Hello there".gsub("e", "3") # results in "H3llo th3r3"


For more complex substitutions you need to use a regexp pattern.
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Find & Replace in Ruby

Postby Wassaka » Thu Sep 29, 2016 1:11 pm

tulamide wrote:The string class has the methods :sub and :gsub, which replace ("substitute") based on following logic:

Code: Select all
mystring = "Hello World".sub("e", "3") # results in "H3llo world"
mystring = "Hello there".sub("e", "3") # results in "H3llo there"


Code: Select all
mystring = "Hello there".gsub("e", "3") # results in "H3llo th3r3"


For more complex substitutions you need to use a regexp pattern.

Thanks you very much!!! :D
Wassaka
 
Posts: 85
Joined: Wed Dec 30, 2015 3:41 am


Return to General

Who is online

Users browsing this forum: No registered users and 56 guests