Hi Vamsi,
One way of doing it:
-----------------------------------
# Convert to array
sentence = "What is your name?".split
# Get the last item in the array
lastword = sentence[sentence.length - 1]
# Replace any unwanted characters such as '?'
lastword.gsub!(/[?!-.]/, '')
puts "My answer is : #{lastword}"
-----------------------------------
Regards,
Lawrence
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of vamsi
Sent: Tuesday, 22 May 2007 7:01
To: [email protected]
Subject: [Wtr-general] how to extract one word from a sentence?
Hi,
Can any one please tell me how to extract the last word from one
senetence using watir scripting?
Example: Sentence: What is your name?
My answer is : name
so i need to extract the name from the above sentence. can any one
please help me to resolve this problem?
Thanks in advance.
Regards
Vamsi
_______________________________________________
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