X-Received: by 2002:a6b:1881:: with SMTP id 123-v6mr2865475ioy.8.1530807051676; Thu, 05 Jul 2018 09:10:51 -0700 (PDT) X-Received: by 2002:aca:4787:: with SMTP id u129-v6mr1462246oia.4.1530807051536; Thu, 05 Jul 2018 09:10:51 -0700 (PDT) Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!d7-v6no2773506itj.0!news-out.google.com!l67-v6ni2805itl.0!nntp.google.com!u78-v6no2746129itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ruby Date: Thu, 5 Jul 2018 09:10:51 -0700 (PDT) In-Reply-To: <442165f5-c8c9-4273-8762-65a86a23bc5c@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=161.69.135.20; posting-account=MGO7qgoAAABvyo26eHVDO00044spH-ws NNTP-Posting-Host: 161.69.135.20 References: <442165f5-c8c9-4273-8762-65a86a23bc5c@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <7f511e6f-cadd-4048-b2b2-e153ca86eb64@googlegroups.com> Subject: Re: Ultimate Guide to Ruby Strings From: Robert Klemme Injection-Date: Thu, 05 Jul 2018 16:10:51 +0000 Content-Type: text/plain; charset="UTF-8" Lines: 41 Xref: csiph.com comp.lang.ruby:7395 On Sunday, February 4, 2018 at 7:00:17 PM UTC+1, Jesus Castello wrote: > Hello! > I wrote an article about ruby string methods on my blog rubyguides. > > You can read it here: > > http://www.rubyguides.com/2018/01/ruby-string-methods/ > > Let me know what you think :) Looks good. Just a few minor nitpicks: My preferred method to test whether a string represents a number is to actually convert it and deal with the error: begin i = Integer(str) printf "%d\n", i rescue ArgumentError puts "Oh, it's not a number!" end Or i = Integer(str) rescue nil if i ... There is another way to extract a sub string: substr = str[/fo+/] and for replacing parts of the string: str[/fo+/] = "bar" (You'll get an IndexError if there is no match.) Cheers robert