静岡理工科大学 菅沼ホーム ActionScript 目次 索引

String クラス

[内容]

  文字列の処理を行うためのクラスです.

継承: String → Object

[プロパティ]

[メソッド]

[使用例]

  1. 使用例1: charAt,charCodeAt,concat,fromCharCode,valueOf -> 表示とそのソースコード
    package {
    	import flash.display.Sprite;
    
    	[SWF(backgroundColor="0xeeffee", width="500", height="200", frameRate="30")]
    
    	public class String_e1 extends Sprite {
    
    		public function String_e1() {
    			var msg : Message = new Message(500, 100);
    			addChild(msg);
    			var a : String = new String("文字列の例 Example of String");
    			msg.tx.appendText("基本文字列 : " + a + "\n");
    					// charAt
    			msg.tx.appendText("charAt(2) : " + a.charAt(2) + "\n");
    					// charCodeAt
    			msg.tx.appendText("charCodeAt(2) : " + a.charCodeAt(2) + "\n");
    					// concat
    			var b : String = a.concat(":Example");
    			msg.tx.appendText("concat : " + b + "\n");
    					// fromCharCode
    			msg.tx.appendText("fromCharCode : " + String.fromCharCode(97,109) + "\n");
    					// valueOf
    			msg.tx.appendText("valueOf : " + a.valueOf() + "\n");
    		}
    	}
    }
    
    package
    {
    	import flash.display.Sprite;
    	import flash.text.TextField;
    	import flash.text.TextFieldType;
    	import flash.text.TextFormat;
    	import flash.text.TextFormatAlign;
    	import flash.events.MouseEvent;
    
    	public class Message extends Sprite
    	{
    		public var tx : TextField;
    		public function Message(w : int, h : int)
    		{
    			tx = new TextField();
    			tx.width = w;
    			tx.height = h;
    			tx.x = 0;
    			tx.y = 0;
    			tx.type = TextFieldType.DYNAMIC;
    			tx.background = true;
    			tx.backgroundColor = 0xffffff;
    			tx.border = true;
    			tx.borderColor = 0x00ff00;
    			tx.multiline = true;
    			var tf : TextFormat = new TextFormat();
    			tf.size = 20;
    			tx.defaultTextFormat = tf;
    			addChild(tx);
    			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    		}
    
    		private function onMouseDown(event:MouseEvent):void
    		{
    			startDrag();
    			addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    			stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    		}
    
    		private function onMouseMove(event:MouseEvent):void
    		{
    			event.updateAfterEvent();
    		}
    
    		private function onMouseUp(event:MouseEvent):void
    		{
    			stopDrag();
    			removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    			stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    		}
    	}
    }
    			

  2. 使用例2: indexOf,search,lastIndexOf,slice,substr,substring,replace,split,match -> 表示とそのソースコード
    package {
    	import flash.display.Sprite;
    
    	[SWF(backgroundColor="0xeeffee", width="500", height="200", frameRate="30")]
    
    	public class String_e2 extends Sprite {
    
    		public function String_e2() {
    			var msg : Message = new Message(700, 100);
    			addChild(msg);
    			var i1 : int;
    			var a : String = new String("This,is,an,Example,of,String,Example,of,String");
    			msg.tx.appendText("基本文字列 : " + a + "\n");
    					// indexOf
    			msg.tx.appendText("indexOf(\"Example\") : " + a.indexOf("Example") + "\n");
    					// search
    			msg.tx.appendText("search(\"Example\") : " + a.search("Example") + "\n");
    					// lastIndexOf
    			msg.tx.appendText("lastIndexOf(\"Example\") : " + a.lastIndexOf("Example") + "\n");
    					// slice
    			msg.tx.appendText("slice(11,18) : " + a.slice(11,18) + "\n");
    					// substr
    			msg.tx.appendText("substr(11,7) : " + a.substr(11,7) + "\n");
    					// substring
    			msg.tx.appendText("substring(11,18) : " + a.substring(11,18) + "\n");
    					// replace
    			msg.tx.appendText("replace(\"Example\",\"*****\") : " + a.replace("Example","*****") + "\n");
    					// split
    			var b : Array = a.split(",");
    			msg.tx.appendText("split : \n");
    			for (i1 = 0; i1 < b.length; i1++)
    				msg.tx.appendText("   " + b[i1] + "\n");
    					// match
    			var ptn : RegExp = /Str.../g;
    			var c : Array = a.match(ptn);
    			msg.tx.appendText("match : \n");
    			for (i1 = 0; i1 < c.length; i1++)
    				msg.tx.appendText("   " + c[i1] + "\n");
    		}
    	}
    }
    
    package
    {
    	import flash.display.Sprite;
    	import flash.text.TextField;
    	import flash.text.TextFieldType;
    	import flash.text.TextFormat;
    	import flash.text.TextFormatAlign;
    	import flash.events.MouseEvent;
    
    	public class Message extends Sprite
    	{
    		public var tx : TextField;
    		public function Message(w : int, h : int)
    		{
    			tx = new TextField();
    			tx.width = w;
    			tx.height = h;
    			tx.x = 0;
    			tx.y = 0;
    			tx.type = TextFieldType.DYNAMIC;
    			tx.background = true;
    			tx.backgroundColor = 0xffffff;
    			tx.border = true;
    			tx.borderColor = 0x00ff00;
    			tx.multiline = true;
    			var tf : TextFormat = new TextFormat();
    			tf.size = 20;
    			tx.defaultTextFormat = tf;
    			addChild(tx);
    			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    		}
    
    		private function onMouseDown(event:MouseEvent):void
    		{
    			startDrag();
    			addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    			stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    		}
    
    		private function onMouseMove(event:MouseEvent):void
    		{
    			event.updateAfterEvent();
    		}
    
    		private function onMouseUp(event:MouseEvent):void
    		{
    			stopDrag();
    			removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    			stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    		}
    	}
    }
    			

  3. 使用例3: localeCompare -> 表示とそのソースコード
    package {
    	import flash.display.Sprite;
    
    	[SWF(backgroundColor="0xeeffee", width="500", height="200", frameRate="30")]
    
    	public class String_e3 extends Sprite {
    
    		public function String_e3() {
    			var msg : Message = new Message(500, 100);
    			addChild(msg);
    			var a : String = new String("Example of String");
    			var b : String = new String("Example of String");
    			var c : String = new String("Example of STRING");
    			msg.tx.appendText("基本文字列(a) : " + a + "\n");
    			msg.tx.appendText("基本文字列(b) : " + b + "\n");
    			msg.tx.appendText("基本文字列(c) : " + c + "\n");
    					// localeCompare
    			msg.tx.appendText("localeCompare(aとb) : " + a.localeCompare(b) + "\n");
    			msg.tx.appendText("localeCompare(aとc) : " + a.localeCompare(c) + "\n");
    		}
    	}
    }
    
    package
    {
    	import flash.display.Sprite;
    	import flash.text.TextField;
    	import flash.text.TextFieldType;
    	import flash.text.TextFormat;
    	import flash.text.TextFormatAlign;
    	import flash.events.MouseEvent;
    
    	public class Message extends Sprite
    	{
    		public var tx : TextField;
    		public function Message(w : int, h : int)
    		{
    			tx = new TextField();
    			tx.width = w;
    			tx.height = h;
    			tx.x = 0;
    			tx.y = 0;
    			tx.type = TextFieldType.DYNAMIC;
    			tx.background = true;
    			tx.backgroundColor = 0xffffff;
    			tx.border = true;
    			tx.borderColor = 0x00ff00;
    			tx.multiline = true;
    			var tf : TextFormat = new TextFormat();
    			tf.size = 20;
    			tx.defaultTextFormat = tf;
    			addChild(tx);
    			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    		}
    
    		private function onMouseDown(event:MouseEvent):void
    		{
    			startDrag();
    			addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    			stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    		}
    
    		private function onMouseMove(event:MouseEvent):void
    		{
    			event.updateAfterEvent();
    		}
    
    		private function onMouseUp(event:MouseEvent):void
    		{
    			stopDrag();
    			removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    			stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    		}
    	}
    }
    			

  4. 使用例4: toLocaleLowerCase,toLocaleUpperCase,toLowerCase,toUpperCase -> 表示とそのソースコード
    package {
    	import flash.display.Sprite;
    
    	[SWF(backgroundColor="0xeeffee", width="500", height="200", frameRate="30")]
    
    	public class String_e4 extends Sprite {
    
    		public function String_e4() {
    			var msg : Message = new Message(500, 100);
    			addChild(msg);
    			var a : String = new String("Example of String");
    			msg.tx.appendText("基本文字列 : " + a + "\n");
    					// toLocaleLowerCase
    			msg.tx.appendText("toLocaleLowerCase : " + a.toLocaleLowerCase() + "\n");
    					// toLocaleUpperCase
    			msg.tx.appendText("toLocaleUpperCase : " + a.toLocaleUpperCase() + "\n");
    					// toLowerCase
    			msg.tx.appendText("toLowerCase : " + a.toLowerCase() + "\n");
    					// toUpperCase
    			msg.tx.appendText("toUpperCase : " + a.toUpperCase() + "\n");
    		}
    	}
    }
    
    package
    {
    	import flash.display.Sprite;
    	import flash.text.TextField;
    	import flash.text.TextFieldType;
    	import flash.text.TextFormat;
    	import flash.text.TextFormatAlign;
    	import flash.events.MouseEvent;
    
    	public class Message extends Sprite
    	{
    		public var tx : TextField;
    		public function Message(w : int, h : int)
    		{
    			tx = new TextField();
    			tx.width = w;
    			tx.height = h;
    			tx.x = 0;
    			tx.y = 0;
    			tx.type = TextFieldType.DYNAMIC;
    			tx.background = true;
    			tx.backgroundColor = 0xffffff;
    			tx.border = true;
    			tx.borderColor = 0x00ff00;
    			tx.multiline = true;
    			var tf : TextFormat = new TextFormat();
    			tf.size = 20;
    			tx.defaultTextFormat = tf;
    			addChild(tx);
    			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    		}
    
    		private function onMouseDown(event:MouseEvent):void
    		{
    			startDrag();
    			addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    			stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    		}
    
    		private function onMouseMove(event:MouseEvent):void
    		{
    			event.updateAfterEvent();
    		}
    
    		private function onMouseUp(event:MouseEvent):void
    		{
    			stopDrag();
    			removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    			stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    		}
    	}
    }
    			

[参照]

トップレベルの関数と定数Number クラス

静岡理工科大学 菅沼ホーム ActionScript 目次 索引