Skip to main content
Participant
October 28, 2010
Answered

[as2] Variable Check

  • October 28, 2010
  • 1 reply
  • 832 views

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,

This topic has been closed for replies.
Correct answer srirama_83

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.

1 reply

srirama_83Correct answer
Inspiring
October 28, 2010

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.

mrbrundleAuthor
Participant
October 28, 2010

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.

mrbrundleAuthor
Participant
October 28, 2010

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