[AS3] 求助!关于字符串 排序拼接的问题
需求是这样的,从xml中获取若干个字符串,格式:“m121”...这样的,第一位都是“m”,后面是数字,我需要在flash中截取后面的数字字符,转换为数字排序后,再把“m...
需求是这样的,从xml中获取若干个字符串,格式:“m121”... 这样的,第一位都是“m”,后面是数字, 我需要在flash中截取后面的数字字符,转换为 数字排序后, 再把“m”拼接回去生成字符串。
以下是代码:
package
{
import flash.display.MovieClip;
public class Test extends MovieClip
{
public var arr1:Array = new Array();
public var arr2:Array = new Array();
public var arr3:Array = ["m112","m113","m121","m122","m123","m146","m151","m161","m136","m148","m1511","m211","m212","m213","m214","m315","m318","m441","m4412"];
public var arr4:Array = new Array();
public var StrName:String;
public function Test(){
for (var k:int = 0; k<19; k++)
{
arr2.push(uint(arr3[k].substr(1,arr3[k].length-1)));
arr2.sort(Array.NUMERIC );
var m:int= arr2.length;
StrName ="m"+String(arr2[k]);
arr1.push(StrName);
trace(arr1);
}
}
}
}
但是结果输出的却是:
m112
m112,m113
m112,m113,m121
m112,m113,m121,m122
m112,m113,m121,m122,m123
m112,m113,m121,m122,m123,m146
m112,m113,m121,m122,m123,m146,m151
m112,m113,m121,m122,m123,m146,m151,m161
m112,m113,m121,m122,m123,m146,m151,m161,m161
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511,m1511,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511,m1511,m1511,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511,m1511,m1511,m1511,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511,m1511,m1511,m1511,m1511,m1511,m4412
求助! 展开
以下是代码:
package
{
import flash.display.MovieClip;
public class Test extends MovieClip
{
public var arr1:Array = new Array();
public var arr2:Array = new Array();
public var arr3:Array = ["m112","m113","m121","m122","m123","m146","m151","m161","m136","m148","m1511","m211","m212","m213","m214","m315","m318","m441","m4412"];
public var arr4:Array = new Array();
public var StrName:String;
public function Test(){
for (var k:int = 0; k<19; k++)
{
arr2.push(uint(arr3[k].substr(1,arr3[k].length-1)));
arr2.sort(Array.NUMERIC );
var m:int= arr2.length;
StrName ="m"+String(arr2[k]);
arr1.push(StrName);
trace(arr1);
}
}
}
}
但是结果输出的却是:
m112
m112,m113
m112,m113,m121
m112,m113,m121,m122
m112,m113,m121,m122,m123
m112,m113,m121,m122,m123,m146
m112,m113,m121,m122,m123,m146,m151
m112,m113,m121,m122,m123,m146,m151,m161
m112,m113,m121,m122,m123,m146,m151,m161,m161
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511,m1511,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511,m1511,m1511,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511,m1511,m1511,m1511,m1511,m1511
m112,m113,m121,m122,m123,m146,m151,m161,m161,m161,m1511,m1511,m1511,m1511,m1511,m1511,m1511,m1511,m4412
求助! 展开
1个回答
展开全部
for (var k:int = 0; k<19; k++)
{
arr2.push(uint(arr3[k].substr(1,arr3[k].length-1)));
}
arr2.sort(Array.NUMERIC );//单独运行,不要在循环中
另外一个循环中执行下三行
var m:int= arr2.length;
StrName ="m"+String(arr2[k]);
arr1.push(StrName);
trace(arr1); //移动动循环外,最后执行
{
arr2.push(uint(arr3[k].substr(1,arr3[k].length-1)));
}
arr2.sort(Array.NUMERIC );//单独运行,不要在循环中
另外一个循环中执行下三行
var m:int= arr2.length;
StrName ="m"+String(arr2[k]);
arr1.push(StrName);
trace(arr1); //移动动循环外,最后执行
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询