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
3 posts
• Page 1 of 1
Find & Replace in Ruby
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
The string class has the methods :sub and :gsub, which replace ("substitute") based on following logic:
For more complex substitutions you need to use a regexp pattern.
- 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
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!!!
- Wassaka
- Posts: 85
- Joined: Wed Dec 30, 2015 3:41 am
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 56 guests