Home Tutorial Flex Flex4 Components String indexOf method example

 
 

Share on Google+Share on Google+
String indexOf method example
Posted on: June 4, 2010 at 12:00 AM
Advertisement
String class method indexOf() is use to find the starting character position of the substring from the string.

String indexOf() method example:-

String class method indexOf() is use to find the starting character position of the substring from the string. The indexOf() method start to search from beginning of the string and matching the substring from substring, if substring is match then it return a index position of the starting character of the substring within string.

Example:-

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init();">

<fx:Script>

<![CDATA[

private function init():void{

var str:String = "Rose India";

var stringposition:Number = str.indexOf("In");

textcontrol1.text = str;

textcontrol2.text = String(stringposition);

}

]]>

</fx:Script>

<s:Panel width="250" height="250" title="String indexOf() method example" backgroundColor="0xEEFFEE">

<s:VGroup>

<mx:Text text=" Main String" fontSize="12" fontWeight="bold"/>

<mx:Text id="textcontrol1"/>

<mx:Text text="String position" fontSize="12" fontWeight="bold"/>

<mx:Text id="textcontrol2"/>

</s:VGroup>

</s:Panel>

</s:Application>

Output:-

Download this code

Advertisement

Related Tags for String indexOf method example:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 4, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com