[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

求助!
展开
 我来答
帐号已注销
2012-12-20 · TA获得超过516个赞
知道大有可为答主
回答量:1788
采纳率:86%
帮助的人:946万
展开全部
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); //移动动循环外,最后执行
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式