Forum Moderators: open

Message Too Old, No Replies

Javascript Detection of a value between two variables?

For example, detecting the full Gecko RV including A and Betas

         

JAB Creations

10:01 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is my UA...

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b2) Gecko/20050525 Firefox/1.0+

The revision number is "1.8b2" and I want to be able to docuement.write "1.8b2".

Using Javascript how do we say...get the value after...

"rv:"

and before...

") Gecko"

RonPK

8:42 am on Jun 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two ways pop up:

1. basic string manipulation, using string.indexOf() and string.substr() or string.substring()

2. pattern matching with regular expressions. Something like
string.match(/rv:.(.*)\)/)
(untested)

JAB Creations

5:32 am on Jun 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I read someplace about indexof but I have no clue how ti implement that however.

RonPK

9:31 am on Jun 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



string.indexOf(substring) returns the position of the first occuring of substring in string.
Example: "webmasterworld".indexOf("world") returns 9 (counting starts at 0).

As for substr() and substring(), I feel the need to refer to the documentation [devedge-temp.mozilla.org] on mozilla.org. They're quite similar, so you can use the one you find the most convenient.