Forum Moderators: open

Message Too Old, No Replies

newbie question seach a variable for a character

         

jeffturl

2:01 pm on Jan 30, 2007 (gmt 0)

10+ Year Member



I apologise if this is a really easy question but i am new to javascript! if i have a variable named x and wish to seach that variable for a - character, then take the following 3 characters after that to do a check on how would i go about this. The last part once i have the characters i can do, but it is the extracting from a variable in the first place. I guess it would be easiest to extract them and place them into another variable?

Any help is appreciated.

Jeff

Fotiman

5:22 pm on Jan 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you mean something like this?

var x = "abcd-efghi";
var dashLocation = x.indexOf("-"); // 4
var threeChars = x.substr( dashLocation + 1, 3 );