Share on Google+Share on Google+

Find Character form String example

Advertisement
String maintain a index position for every character in the string. The first character index position is 0.

Find characters from String example in Action Script3:-

String maintain a index position for every character in the string. The first character index position is 0.  String provide charAt() method to find out the character in the string with the help of index position, and also find the character code using charCodeAt() method. User can see how to use these methods in the application in this example.

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[

import mx.controls.Text;

import mx.controls.Alert;

private function init():void{

var str:String = "Brijesh";

for (var index:int = 0; index < str.length; index++)

{

var mytext:Text = new Text();

mytext.text = (String)(str.charAt(index)+ "-"+ str.charCodeAt(index));

myVGroup.addElement(mytext);

}

}

]]>

</fx:Script>

<s:Panel width="200" height="250" title="String characters Panel" backgroundColor="0x81B5AA">

<s:VGroup id="myVGroup">

</s:VGroup>

</s:Panel>

</s:Application>

In this example we have created a string and find out the length of the string and apply the string.charAt()  and string.charCodeAt()  methods to find out characters form the string. User can see the out put that gives a individual character and character code both.

Output:-

Download this code

Advertisements

Advertisement

Posted on: June 3, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.