On Tue, May 6, 2008 at 9:46 AM, Chris <[EMAIL PROTECTED]> wrote: > > Essentially I would like to do: > "Mr. Mike Smith" -> "Mike Smith" > > when I use: row[0].delete "Mr"
Since neither JS nor Prototype has a delete method for string objects, I assume you're referring to Ruby's String::delete method. That's probably better suited for a Ruby or Rails list, (since this list is specifically geared towards Prototype) but I'll see if I can help (I'm not a Ruby expert by any means). > The string becomes "ike Smith" for some reason. Here's what delete does, according to the Ruby docs: "Returns a copy of str with all characters in the intersection of its arguments deleted." That means that when you pass, for example, "Mr" to delete, it's going to delete /every/ "M" and /every/ "r" it finds in the string. As far as I can tell, in your case you should actually be getting ". ike Smith" back from delete (not "ike Smith"). If you pass "Mr." to delete, then every period character is going to be removed as well, giving you " ike Smith" (note the leading space). Passing "Mr. " (with a trailing space) gets you "ikeSmith". I'm sure you can tell that delete's probably not the method you need ;) You could probably use sub, though, which seems to do closer to what you're trying to accomplish. You need to pass the string you're looking for and what you want to replace it with. For example: row[0].sub 'Mr. ', '' => "Mike Smith" Note that you can also use regexes instead of string arguments, in which case the example Kangax provided will work perfectly. The Ruby docs for sub are at <http://www.ruby-doc.org/core/classes/String.html#M000831>. (You might want to check out gsub as well.) Hope that helps. :Dan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
