'test    ' =~ /test/

returns zero because it is position in string that he found the match (it is
zero based, so first character in string has number 0).

'   test    ' =~ /test/ #(add three spaces before test)

would return 3.

It returns nil when no match is found.

rstrip is part of Ruby (String class) and not part of Watir.

Try reading this book if you are really serious about using Watir, it will
all make much more sense after you read it.

http://www.whytheluckystiff.net/ruby/pickaxe/

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mark Gargan
Sent: Wednesday, October 19, 2005 12:59 PM
To: '[email protected]'
Subject: Re: [Wtr-general] String matching

Hi Zeljko,

        Thanks a million for the help.

I've run the line
'test                           ' =~ /test/

in the fxri and it return a value of zero.
Is zero the correct value or should it not be true or 1?
The value is nil when I put in something like 
'test                           ' =~ /tet/

I couldn't locate the rstrip function in the WATIR api
but it's exactly what I'm looking for. 

Thanks again Zeljko,
Mark.

-----Original Message-----
From: Zeljko Filipin [mailto:[EMAIL PROTECTED]
Sent: 19 October 2005 11:50
To: [email protected]
Subject: Re: [Wtr-general] String matching


I am not shure what do you want to do.

1) If you want to see if a string contains another string you can do it like
this:

'test                           ' =~ /test/

2) if you want to delete spaces from the end of the string you can do it
like this:

'test                           '.rstrip

or like this

'test                           '.delete(' ')

Zeljko

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mark Gargan
Sent: Wednesday, October 19, 2005 12:40 PM
To: wtrList (E-mail)
Subject: [Wtr-general] String matching

Hi folks,

        I'm reading a value from a textArea using text_field however all the
whitespace after the value is 
included i.e. I'm getting back a string like
"test                                                   "
I'm trying to match a preset value "test" to this but I can't get the string
matches method to work?

I've tried 
str1= "test                                                     "
str2 = "test"

str1.matches("^"+str2+" *$)

but it doesn't seem to match. My regexp isn't as strong as it could be but
I'd appreciate any help.

Perhaps there's some sort of trim function available? 

Thanks,
Mark.

Mark Gargan             
Software Developer
Allfinanz Distribution Software
<<http://www.allfinanz.com/>>
Direct Line: 213 5115
Fax: +353 1 295 2554 
<<mailto:[EMAIL PROTECTED]>>


_______________________________________________
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
_______________________________________________
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

Reply via email to