2016-04-11 2 views
0

Ich habe gerade angefangen zu lernen Actionscript und ich frage mich, wie konnte ich verkürzen diese if-AnweisungShorten if-Anweisung Actionscript 3

if (txtInputTemp.charAt(track - 1) == "a" || txtInputTemp.charAt(track - 1) == "b" || txtInputTemp.charAt(track - 1) == "c" || txtInputTemp.charAt(track - 1) == "d" || txtInputTemp.charAt(track - 1) == "e" || txtInputTemp.charAt(track - 1) == "f" || txtInputTemp.charAt(track - 1) == "g" || txtInputTemp.charAt(track - 1) == "h" || txtInputTemp.charAt(track - 1) == "i" || txtInputTemp.charAt(track - 1) == "j" || txtInputTemp.charAt(track - 1) == "k" || txtInputTemp.charAt(track - 1) == "l" || txtInputTemp.charAt(track - 1) == "m" || txtInputTemp.charAt(track - 1) == "n" || txtInputTemp.charAt(track - 1) == "o" || txtInputTemp.charAt(track - 1) == "p" || txtInputTemp.charAt(track - 1) == "q" || txtInputTemp.charAt(track - 1) == "r" || txtInputTemp.charAt(track - 1) == "s" || txtInputTemp.charAt(track - 1) == "t" || txtInputTemp.charAt(track - 1) == "u" || txtInputTemp.charAt(track - 1) == "v" || txtInputTemp.charAt(track - 1) == "w" || txtInputTemp.charAt(track - 1) == "x" || txtInputTemp.charAt(track - 1) == "y" || txtInputTemp.charAt(track - 1) == "z" || txtInputTemp.charAt(track - 1) == "." || txtInputTemp.charAt(track - 1) == "'" || txtInputTemp.charAt(track - 1) == "-" || txtInputTemp.charAt(track - 1) == " ") { } 

Jede Hilfe sehr geschätzt wird.

Antwort

2

Er kann a-z in die Bereichsspezifikation umschreiben.

somechar>="a" && somechar<="z" 

Aber ich habe keine Ahnung, wie diese Symbole zu verkürzen.

== "." 
== "'" 
== "-" 
== " " 


var somechar:String = txtInputTemp.charAt(track - 1); 
if ((somechar>="a" && somechar<="z")||somechar == "."||somechar == "'"||somechar == "-"||somechar == " ") 
{ 
    // do something 
} 

Arbeitsbeispiel: http://wonderfl.net/c/A9Hv

Option2: Verwenden array.indexOf(char) == -1 oder nicht.

var someArray: Array = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",".","'","-"," "]; 

var somechar:String = txtInputTemp.charAt(track - 1); 

if (someArray.indexOf(somechar) != -1) 
{ 
    // Do something 
} 
+0

Dies ist genau das, was ich brauchte, danke für die Hilfe. – will

+0

@will Danke, ich habe Antwortoption2 aktualisiert. –