Assuming that the first part of the label is always the same, then gsub is one of many ways:
irb(main):017:0> x = 'Good Morning, Billy Bob Joe' => "Good Morning, Billy Bob Joe" irb(main):018:0> x.gsub(/Good Morning, /, '') => "Billy Bob Joe" -andy ----Original Message Follows---- From: "Paul Carvalho" <[EMAIL PROTECTED]> Reply-To: [email protected] To: [email protected] Subject: [Wtr-general] How do I set the end of a string to a variable? Date: Tue, 16 May 2006 14:07:28 -0400 Okay. I know that I should know this, but knowing that doesn't mean that I know it. arrrg. This is a Ruby string manipulation question, not really a Watir question. I have this label on a web page - we'll call it PageHeadingLabel - and the contents change based on selected user. I need to know how to capture the *last* part of that string to a variable. Here's the code that calls up the text: $main_frame.span(:id, /PageHeadingLabel/).text And the output is something like: "Good Morning, <user name>" e.g. "Good Morning, Bob" or "Good Morning, Jamaican Bobsled Team" or whatever. I *need* to capture the user name to a variable (let's call it 'user_name') -> I have looked through all the String class methods, but I haven't found anything straightforward that will help me output the last part of a random-length string. I managed to get the Element Reference [] to spit out what I need but it's kind of gross-looking (mostly because I don't want to work with intermediate variables). I browsed through the Regular Expression stuff, but I still haven't had a chance to read up on it. My amateur re commands keep returning true, false, nil, etc. but not actual strings. Does anyone know of a simple way to set a variable to something like this: user_name = $main_frame.span(:id, /PageHeadingLabel/).text (from ', ' to the end) ? help. please. _______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general _______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
