String comparison example


 

String comparison example

There are many comparison operators for comparing strings like <, <=, !=, ==, =>, and >.

There are many comparison operators for comparing strings like <, <=, !=, ==, =>, and >.

String comparison example:-

There are many comparison operators for comparing strings like <, <=, !=, ==, =>, and >. Action script  compare strings on the character code value for each character in the string. In the Action script3, every comparison process of characters from left to right. These comparison operators can be used with conditional statements. In the given example, we can use "= =" operator for compare two strings.

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 str1:String = "Brijesh";

var str2:String = "brijesh";

myText1.text = "This is first String :" + str1;

myText2.text = "This is second String :" + str2;

if(str1 == str2){

myText3.text = "Yes";

}

else{

myText3.text = "No";

}

if("Brijesh" == "Brijesh"){

myText4.text = "Yes";

}

else{

myText4.text = "No";

}

if("A" == "a"){

myText5.text = "Yes";

}

else{

0

myText5.text = "No";

}

}

1

]]>

</fx:Script>

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

2

<s:VGroup>

<mx:Text id="myText1"/>

<mx:Text id="myText2"/>

3

<s:HGroup>

<mx:Text text="'Brijesh' == 'brijesh'"/>

<mx:Text id="myText3"/>

4

</s:HGroup>

<s:HGroup>

<mx:Text text="'Brijesh' == 'Brijesh'"/>

5

<mx:Text id="myText4"/>

</s:HGroup>

<s:HGroup>

6

<mx:Text text=" 'A' == 'a' "/>

<mx:Text id="myText5"/>

</s:HGroup>

7

</s:VGroup>

</s:Panel>

&</s:Application>

8

 Output:-

Download this code

9

Ads