[Wtr-general] How do I set the end of a string to a variable?

Paul Carvalho tester.paul at gmail.com
Tue May 16 14:07:28 EDT 2006


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wtr-general/attachments/20060516/cc286e65/attachment.html 


More information about the Wtr-general mailing list