Use indexOf( ) in a while statement to get the indices of every occurrence of a substring : IndexOf lastIndexOf : String Flash / Flex / ActionScript examples
Use indexOf( ) in a while statement to get the indices of every occurrence of a substring
package{ import flash.display.Sprite;
public class Main extends Sprite{ public function Main(){ var example:String = "This string contains the word cool. Very cool. Yes, cool."; var index:int = -1; while ( ( index = example.indexOf( "cool", index + 1 ) ) != -1 ) {
trace( "String contains word cool at index " + index ); } } } }
Related Scripts with Example Source Code in same category :