//-------------------------------------------------------------------------- //可以生成一个函数,该函数可以由任意组合的N进制与10进制数进行转换 //用一个字符,表达多个字符,可以理解压缩或加密 function X2T(N:String):Function { var f:Function = function (x:String, fx:Boolean) { var jzArray:String = N; var jzl:Number = N.length; var f2:Function = function (n:Number, str:String):String { var jzArray2:String = N; var jzl2:Number = N.length; if (n.toString().length<2) { str = jzArray2.charAt(n)+str; return str; } else { var shang:Number = Math.floor(n/jzl2); var yu:Number = int(n%jzl2); //trace(jzl2+"--- "+shang+":"+yu); str = jzArray2.charAt(yu)+str; if (shang == 0) { return str; } str = this.call(this, shang, str); //Debug.traceAllObj(this); return str; } }; if (fx) { var n:Number = 0; var l:Number = x.length; for (var i = 0; iwaitTime) { tf.text = str.substr(0, clearCount); tf.text = tf.text+ranHolder.substr(clearCount, ranCount-clearCount); clearCount++; } ranCount++; wait++; } else { delete this.onEnterFrame; } }; } // createEmptyMovieClip("tmc", 0).createTextField("t_txt", 0, 0, 0, 100, 20).text = "typing text effect"; encryption(tmc, tmc.t_txt, tmc.t_txt.text, 5); //-------------------------------------------------------------------------- //截取开始到指定长度的字符串,并后面加省略号 String.prototype.shenglue = function(n:Number) { return (substring(this, 0, n)+"......"); }; str = "为国内的FLASH产业发展做一些力所能及的事"; trace(str.shenglue(12)); //-------------------------------------------------------------------------- // 去掉网页代码里的标签 String.prototype.removeHTML = function() { var temp, i; var xStr = this; var total = xStr.length; for (i=0; i"); i += x; } } return (temp); }; // Example testStr = "This is my test.
My line break was here and another one

happened here.
The end!"; trace("Trace testStr: "+testStr); newStr = testStr.removeHTML(); trace("Trace newStr: "+newStr); //-------------------------------------------------------------------------- // CDATA编码转换 // ? Ivan Dembicki, dembicki@narod.ru String.prototype.encodingToCDATA = function() { return new XMLnode(3, this).toString(); }; String.prototype.encodingFromCDATA = function() { return new XML(this).firstChild.nodeValue; }; // Example trace("text to convert:"); my_CDATA_string = "bold text"; trace("\t\t"+my_CDATA_string); trace("converted to CDATA:"); my_CDATA_string = my_CDATA_string.encodingToCDATA(); trace("\t\t"+my_CDATA_string); trace("check:"); my_CDATA_string = new XML("bold text]]>").firstChild.toString(); trace("\t\t"+my_CDATA_string); my_CDATA_string = my_CDATA_string.encodingFromCDATA(); trace("converted from CDATA:"); trace("\t\t"+my_CDATA_string); //-------------------------------------------------------------------------- // 乱序字符串 String.prototype.shuffle = function() { return this.split("").sort( function(){return random(3)-1;} ).join(""); }; ASSetPropFlags(Array.prototype, "shuffle", 1, true); // Example test_str = "abcdef"; trace(test_str.shuffle()); //-------------------------------------------------------------------------- // 手机面板上的字符到数字的转换 String.prototype.toPhonePad = function() { var i, s, r = '', sp = ' 12a2b2c2d3e3f3g4h4i4j5k5l5m6n6o6p7q7r7s7t8u8v8w9x9y9z9+0', a = this.toLowerCase(); for (i=0; i1 ? r += s[1].charAt(0) : r += a.charAt(i); } else { r += a.charAt(i); } } return r; }; // Example var s = 'Hello-Dolly'; trace(s.toPhonePad()); //-------------------------------------------------------------------------- // 特定标识符间替换,提取 String.prototype.extractBetween = function( starts, ends, inclusive){ var ary = []; var str = this; var sl = starts.length; var el = ends.length; var s,e; while (str.length) { s = str.indexOf(starts); if (s == -1) return ary; e = str.indexOf(ends, s+sl); if (e == -1) return ary; if (inclusive) ary.push(str.substring(s, e) + ends); else ary.push(str.substring(s+sl, e)); str = str.substr(e+el); } return ary; } String.prototype.replaceBetween = function( starts, ends, replace, inclusive){ var r = ""; var str = this; var sl = starts.length; var el = ends.length; var s,e; while (str.length) { s = str.indexOf(starts); if (s == -1) return r + str; e = str.indexOf(ends, s+sl); if (e == -1) return r + str; if (inclusive) r += str.substr(0, s); else r += str.substr(0, s) + starts + replace + ends; str = str.substr(e+el); } return r; } // Example text = "workHard = function(/# args? #/) /# this is where you work hard #/return true; }"; trace(text.replaceBetween("/#", "#/", "", true)); // workHard = function() return true; } trace(text.replaceBetween("/#", "#/", " comment ", false)); // workHard = function(/# comment #/) /# comment #/return true; } text = "Sometimes {people} like to {eat} the most {fatty} foods when eat {out}."; trace(text.extractBetween("{", "}", true)); // {people},{eat},{fatty},{out} trace(text.extractBetween("{", "}", false)); // people,eat,fatty,out //-------------------------------------------------------------------------- // 字符串中子字符串替换 // Quick and tiny string replace methods by PixelCube String.prototype.replace = function(what_str, to_str) { return this.split(what_str).join(to_str); }; ASSetPropFlags(String.prototype,"replace",1,true); // Test var my_str = new String("Run...run run, pixels!"); trace(my_str.replace('run', 'stop')); //-------------------------------------------------------------------------- // 字符串中取右边算起的子字符串 String.prototype.right = function(nbrOfChars) { return this.substr((this.length-nbrOfChars), (nbrOfChars)); }; // Example: str = "main_content.swf"; trace(str.right(4)); // ".swf" //-------------------------------------------------------------------------- // 数字前填充字符,达到指定长度 Pad out string with characters. String.prototype.string_padding = function(fill, no) { var pad = ""; while (this.length+pad.length