主题:求从小到大和从大到小排序
a1999zqw
[专家分:0] 发布于 2009-10-22 14:52:00
给出任意字串,求从小到大和从大到小排序?字串是由N个数字加‘/’组合在一起的
如a='15/464/4694/1/1456/02/1648/01/16644/9/865/461/005'会得出
a1='1/1/2/5/9/15/461/464/864/1456/1648/4694/16644'
a2='16644/4694/1648/1456/864/464/461/15/9/5/2/1/1'
a3='01/1/02/005/9/15/461/464/864/1456/1648/4694/16644'
a4='16644/4694/1648/1456/864/464/461/15/9/005/02/1/01'
如何快速得到a1,a2,a3,a4
回复列表 (共6个回复)
沙发
martine [专家分:4950] 发布于 2009-10-22 15:04:00
按"/"逐个截取到数据库中排序后再加
板凳
a1999zqw [专家分:0] 发布于 2009-10-22 15:58:00
楼上方法,早用过了,太慢
3 楼
Vii [专家分:1130] 发布于 2009-10-22 16:16:00
ALINES()直接转到数组.
4 楼
a1999zqw [专家分:0] 发布于 2009-10-22 19:52:00
说详细点,不太懂数组
5 楼
Vii [专家分:1130] 发布于 2009-10-22 21:33:00
CLOSE ALL
SET SAFETY OFF
CREATE CURSOR Temp(C C(10),N N(10))
A='15/464/4694/1/1456/02/1648/01/16644/9/865/461/005'
ALINES(cStr,A,0,'/')
FOR I = 1 TO ALEN(cStr)
INSERT INTO Temp(C,N) VALUES (cStr(I),VAL(cStr(I)))
ENDFOR
SELECT N FROM Temp ORDER BY N
SELECT N FROM Temp ORDER BY N DESC
SELECT C FROM Temp ORDER BY N,C ASC
SELECT C FROM Temp ORDER BY N DESC
6 楼
sywzs [专家分:5650] 发布于 2009-10-23 06:32:00
aa='15/464/4694/1/1456/02/1648/01/16644/9/865/461/005'+"/"
n=OCCURS("/",aa)
DIMENSION csz(n,2)
FOR i=1 TO n
csz(i,1)=CHRTRAN(PADL(LEFT(aa,AT("/",aa)-1),8)," ","0")
csz(i,2)=PADL(LEFT(aa,AT("/",aa)-1),8)
aa=SUBSTR(aa,AT("/",aa)+1)
NEXT
ASORT(csz,-1,-1,0)
STORE "" TO a1,a2,a3,a4
FOR i=1 TO n
a1=a1+ALLTRIM(STR(VAL(LTRIM(csz(i,2)))))+IIF(i<n,"/","")
a2=a2+ALLTRIM(STR(VAL(LTRIM(csz(n-i+1,2)))))+IIF(i<n,"/","")
a3=a3+LTRIM(csz(i,2))+IIF(i<n,"/","")
a4=a4+LTRIM(csz(n-i+1,2))+IIF(i<n,"/","")
NEXT
我来回复