In the Action Script3, String is uses "+" operator for concatenate two strings.
In the Action Script3, String is uses "+" operator for concatenate two strings.String Concatenation process example:-
In the Action Script3, String is uses "+" operator for concatenate two strings. Concatenation of strings is a process to append one string sequentially in to end of the other string. String class also provided concat() method to concatenate two strings. In this example we have used both "+" and concat() method to concatenate two strings. In this example user can see different types of concatenate processes.
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.Alert; private function init():void{ // first type var str1:String = "Brijesh"; var str2:String = " Kumar"; var str3:String = str1 + str2; textcontrol1.text = str3; // second type var str4:String = str1 + " Singh"; textcontrol2.text = str4; // third type var str5:String = "Raj"; var str6:String = "Singh"; var str7:String = str5.concat(" ", str6); textcontrol3.text = str7; // forth type var str8:String = "Sum of numbers = "; var num1:Number =12; var num2:Number =15; var num3:Number = (num1 + num2); var str9:String = str8 + num3; textcontrol4.text = str9; } ]]> </fx:Script> <s:Panel width="225" height="300" title="String concatenate example" backgroundColor="0xEEFFEE"> <s:VGroup> <mx:Text id="textmsg1" text="First type string concatenation" fontSize="12" fontWeight="bold"/> <mx:Text id="textcontrol1"/> <mx:Text id="textmsg2" text="Second type string concatenation" fontSize="12" fontWeight="bold"/> <mx:Text id="textcontrol2"/> <mx:Text id="textmsg3" text="Third type string concatenation" fontSize="12" fontWeight="bold"/> <mx:Text id="textcontrol3"/> <mx:Text id="textmsg4" text="Forth type string concatenation" fontSize="12" fontWeight="bold"/> <mx:Text id="textcontrol4"/> </s:VGroup> </s:Panel> </s:Application> |
Output:-