字符串拆分
如何用将下表A522K0 22OK C108,C301-C306,C411,C501
拆分成
A522K0 22OK C108
A522K0 22OK C301
A522K0 22OK C302
A522K0 22OK C303
A522K0 22OK C304
A522K0 22OK C305
A522K0 22OK C306
A522K0 22OK C411
A522K0 22OK C501
CLEAR ALL CLEAR DIMENSION aSplit[1] cString = "C108, c301 -C306,A411,C501," IF Split(@aSplit, cString, "C") > 0 FOR nIndex = 1 TO ALEN(aSplit, 1) ? aSplit[nIndex] NEXT ENDIF CLEAR ALL RETURN FUNCTION Split(taSplit, tcString, tcBegin) LOCAL laTemp[1], lnBeginLength, lnLines, lnCount lnBeginLength = LEN(tcBegin) lnCount = 0 lnLines = ALINES(laTemp, tcString, 1+4+8, ",") IF lnLines > 0 LOCAL lnLine FOR lnLine = 1 TO lnLines IF UPPER(LEFT(laTemp[lnLine], lnBeginLength)) == UPPER(tcBegin) lnCount = lnCount + 1 DIMENSION taSplit[lnCount] LOCAL lnPos lnPos = AT("-", laTemp[lnLine]) IF lnPos > 0 taSplit[lnCount] = LEFT(laTemp[lnLine], lnPos - 1) LOCAL lnFrom, lnTo, lnIndex lnFrom = VAL(SUBSTR(laTemp[lnLine], lnBeginLength + 1, lnPos - lnBeginLength - 1)) + 1 lnTo = VAL(SUBSTR(SUBSTR(laTemp[lnLine], lnPos + 1), lnBeginLength + 1)) FOR lnIndex = lnFrom TO lnTo lnCount = lnCount + 1 DIMENSION taSplit[lnCount] taSplit[lnCount] = tcBegin + TRANSFORM(lnIndex) NEXT ELSE taSplit[lnCount] = laTemp[lnLine] ENDIF ENDIF NEXT ENDIF RETURN lnCount ENDFUNC
[此贴子已经被作者于2015-12-7 23:09编辑过]