From: Aldric Giacomoni on 17 Nov 2009 14:13 John Mcleod wrote: > what is happening here? > h.tr(" ", "_").delete("^a-zA-Z0-9_#") > > it looks like you're checking a table row for an instance of " " and > replacing with "_" > but I'm unsure of the ".delete("^a-zA-Z0-9_")" > > John http://rubular.com/ is your best friend. -- Posted via http://www.ruby-forum.com/.
From: James Edward Gray II on 17 Nov 2009 14:15 On Nov 17, 2009, at 1:13 PM, Aldric Giacomoni wrote: > John Mcleod wrote: >> what is happening here? >> h.tr(" ", "_").delete("^a-zA-Z0-9_#") >> >> it looks like you're checking a table row for an instance of " " and >> replacing with "_" >> but I'm unsure of the ".delete("^a-zA-Z0-9_")" >> >> John > > http://rubular.com/ is your best friend. I didn't use any regular expressions. ;) James Edward Gray II
From: James Edward Gray II on 17 Nov 2009 14:19 On Nov 17, 2009, at 12:58 PM, John Mcleod wrote: > In your code... > :header_converters => lambda { |h| h.tr(" ", > "_").delete("^a-zA-Z0-9_")}, > > what is happening here? > h.tr(" ", "_").delete("^a-zA-Z0-9_#") > > it looks like you're checking a table row for an instance of " " and > replacing with "_" tr(), for transliterate, is used to replace characters. You are right that I'm using it to switch all spaces to underscores. > but I'm unsure of the ".delete("^a-zA-Z0-9_")" delete() allows me to list characters I want to remove. It understands simple ranges, like a-z and 0-9. Also, if the first character is a ^, the entire character set is negated. Thus my call means delete all non letters, numbers, and underscore characters. James Edward Gray II
From: Aldric Giacomoni on 17 Nov 2009 14:19 James Edward Gray II wrote: > On Nov 17, 2009, at 1:13 PM, Aldric Giacomoni wrote: > >> http://rubular.com/ is your best friend. > I didn't use any regular expressions. ;) > > James Edward Gray II I'll be quiet now :-) My brain parsed it correctly and categorized it incorrectly. -- Posted via http://www.ruby-forum.com/.
From: John Mcleod on 17 Nov 2009 14:49 So to delete or remove say additional special characters, you would add additional characters to the range? h.tr(" ", "_").delete("^a-zA-Z0-9_#$-") -- Posted via http://www.ruby-forum.com/.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: How to dynamically include a module and update top level? Next: help with parsing |