string类的常用方法

 

做一个 string类的常用方法的跨语言笔记

 

 

1 转义符

 

\b\t\f 换页

\u4f8e unicode 

\n 换行

\x3e ascii

\r 回车

 

定位

 

str[]  c

str.charAt(5) :String  AS3

str.charCodeAt(3):Number    AS3

转码

String.fromCharCode(67,68,78)

比较

==

=== 

(区别在地址

(ref or 内容

分割 

var arr:Array=str.split("#")

arr[0] arr[1]

查找

str.indexOf(keyword)

返回 第一个int 没有就 -1

str.lastIndexOf(keyword)

顾名思义

 

str.search(正则)

返回第一个 or -1

 

str.match(正则  /g):Array

Array<string> -v- 这个是C++语法了  Array里面装string 不是 index 哦~~

 

str.replace("xxx","bbb") 第一个xxx->bbb

str.replace(/xx/g,"bbb") all xxx->bbb

 

字串

slice  substr  substring

str.slice( first:int ,last:int):String

str.substr( first:int , length:int):String

str.substring( a nod:int , another nod :int)String 

str.substring(3,-1 ) <=> 0,3

 

大小写

str.toLowerCase()

str.toUpperCase()

 

空白处理——自己写吧  AS3是没有滴!!!

public function trim(str :String):String

{

const blank:String="\x20\u3000\n\t\r")

var i:int,c:String

  for(str++)

  {

    if(blank.indexOf(str.cjarAt(i))==-1)

      break;

    str=str.substr(i);

  }

  for (str --)

  {

     if(blank.indexOf(str.cjarAt(i))==-1)

      break;

    str=str.substr(0,i+1)

  }

  return str;

}

 

 

 

 

 

 

posted on 2011-01-21 19:17  瞧瞧  阅读(268)  评论(0编辑  收藏  举报