03.07.2013 Views

Guide de reference du langage ActionScript 2.0 - PowWeb

Guide de reference du langage ActionScript 2.0 - PowWeb

Guide de reference du langage ActionScript 2.0 - PowWeb

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

trace(address_str); // output: dog@house.net<br />

in<strong>de</strong>xOf (métho<strong>de</strong> String.in<strong>de</strong>xOf)<br />

public in<strong>de</strong>xOf(value:String, [startIn<strong>de</strong>x:Number]) : Number<br />

Recherche la chaîne et renvoie la position <strong>de</strong> la première occurrence <strong>de</strong> value détectée au<br />

niveau <strong>de</strong> ou après startIn<strong>de</strong>x dans la chaîne appelante. Cet in<strong>de</strong>x est basé sur zéro, ce qui<br />

signifie que le premier caractère d'une chaîne est considéré comme étant à l'in<strong>de</strong>x 0, pas<br />

l'in<strong>de</strong>x 1. Si value n'est pas détecté, la métho<strong>de</strong> renvoie -1.<br />

Disponibilité : <strong>ActionScript</strong> 1.0 ; Flash Player 5<br />

Paramètres<br />

value:String - Chaîne ; sous-chaîne à rechercher.<br />

startIn<strong>de</strong>x:Number [facultatif] - Entier spécifiant l'in<strong>de</strong>x <strong>de</strong> départ <strong>de</strong> la recherche.<br />

Valeur renvoyée<br />

Number - Position <strong>de</strong> la première occurrence <strong>de</strong> la sous-chaîne spécifiée ou -1.<br />

Exemple<br />

Les exemples suivants utilisent in<strong>de</strong>xOf() pour renvoyer l'in<strong>de</strong>x <strong>de</strong> caractères et <strong>de</strong> souschaînes<br />

:<br />

var searchString:String = "Lorem ipsum dolor sit amet.";<br />

var in<strong>de</strong>x:Number;<br />

in<strong>de</strong>x = searchString.in<strong>de</strong>xOf("L");<br />

trace(in<strong>de</strong>x); // output: 0<br />

in<strong>de</strong>x = searchString.in<strong>de</strong>xOf("l");<br />

trace(in<strong>de</strong>x); // output: 14<br />

in<strong>de</strong>x = searchString.in<strong>de</strong>xOf("i");<br />

trace(in<strong>de</strong>x); // output: 6<br />

in<strong>de</strong>x = searchString.in<strong>de</strong>xOf("ipsum");<br />

trace(in<strong>de</strong>x); // output: 6<br />

in<strong>de</strong>x = searchString.in<strong>de</strong>xOf("i", 7);<br />

trace(in<strong>de</strong>x); // output: 19<br />

in<strong>de</strong>x = searchString.in<strong>de</strong>xOf("z");<br />

trace(in<strong>de</strong>x); // output: -1<br />

String 1171

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!