5 Replies Latest reply on Oct 28, 2010 12:08 PM by Rothrock

# [as2] Variable Check

Hello guys, I have a problem and I hope to explain better.
I'm creating a website using SWFAddress. No problem, apart from this thing.

Suppose I receive an external variable called pippo that has this value:
nome/15.

I need to create an IF statement, which makes a thing like this: if pippo is == nome/ + a number and if this number is greater than 0 (so it must check just the fact that 15 is a number ), then assigns that number to the variable pippo_numero.

I searched everywhere and I don't have found, in essence,
a function that identifies in a variable composed of characters and numbers, if there's a number and what is it. I ask you if exists this function and if you were so kind to give me an example, saved my life.

Thank you in advance for your time,

• ###### 1. Re: [as2] Variable Check

var str:String ="nome/15"  // (considering pippo =nome/15 )

var sr:String = str.substr(5, 2);

// if 'nome/' is same for all value and only number changes

// you can also use

//var len:Number=str.length

//var sr:String = str.substr(5, len);

//will be useful for single digit numbers like 0,1,..9

trace(sr) //will trace 15

if (Number(sr)>0) {

pippo_numero=Number(sr);

}

Hope this is what you are looking at.

• ###### 2. Re: [as2] Variable Check

Sriram is perfect, thank you very much. I forgot one thing, in terms of the IF statement, must be there that the first part of the variable is "nome/" how can I translate that in as?

Thanks again for your time, you were very kind.

• ###### 3. Re: [as2] Variable Check

Forget it. I solved.

var first_str:String = str.substring(0, 5)

and in the if statement (first_str == "nome/" && Number(sr)>0);

Ok thank you very much again srirama

• ###### 4. Re: [as2] Variable Check

Welcome ,anytime

• ###### 5. Re: [as2] Variable Check

Casting as Number() can work, but it can also occasionally have unexpected failures.

I prefer to use parseInt() and parseFloat().