...

View Full Version : elementAt(str, idx, delim)



snoodle
06-19-2007, 12:17 PM
Sometimes the simplest things stop me dead in my tracks...

Could someone please explain why I can't use the string function, "elementAt"? I'm simply trying to parse a long comma delimited string. Writing it with substring and indexOf is fine, but I'd like to fully understand what's going on. Do I need the WMLScript String Library to use elementAt? Do I need to pay for that library? Where do I even download it?Some of these sites are so confusing. Also, since my string can get kind of lengthy, what is the function that will do this the quickest? I don't know, maybe I'm just tired, but it would sure be nice to have this all explained when I wake up in the morn.

Thanks to all my helpers out there.

digital-ether
06-19-2007, 01:21 PM
Sometimes the simplest things stop me dead in my tracks...

Could someone please explain why I can't use the string function, "elementAt"? I'm simply trying to parse a long comma delimited string. Writing it with substring and indexOf is fine, but I'd like to fully understand what's going on. Do I need the WMLScript String Library to use elementAt? Do I need to pay for that library? Where do I even download it?Some of these sites are so confusing. Also, since my string can get kind of lengthy, what is the function that will do this the quickest? I don't know, maybe I'm just tired, but it would sure be nice to have this all explained when I wake up in the morn.

Thanks to all my helpers out there.

I don't think elementAt() is a native javascript string method. A native method would look like:


str.elementAt(idx, delim)

instead of:


elementAt(str, idx, delim)

Here's a good number of examples on how to test a string in an Array:
http://www.snook.ca/archives/javascript/testing_for_a_v/

It might give you some Ideas.

jkd
06-19-2007, 01:36 PM
Why not just say str.split(delim)[idx] ?

snoodle
06-19-2007, 06:48 PM
thank you! split does the trick just fine.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum