LEX 'PARTSTR'* A LEX File to split a string into two parts. ID #EC * J.Elhay, 24/11/87. MSG 0 POLL 0 ENTRY PART CHAR #F * a function KEY 'PSTR$' * Syntax: PSTR$(A$,n1,n2)=A$[1,n1] if n2=1 TOKEN 48 * =A$[n1+1] if n2=0 ENDTXT * Error for other n2, and if n1>LEN(A$) or n1<0. RNDAHX EQU #136CB * Pop a real number as a HEX integer ARGERR EQU #0BF19 * Invalid argument error exit XXHEAD EQU #1A44E * Undo ADHEAD ADHEAD EQU #181B7 * Add header to string on stack D=AVMS EQU #1A460 * needed by ADHEAD REV$ EQU #1B38E * Reverse a string on the stack EXPR EQU #0F23C * function exit for item on stack NIBHEX 88433 * A string and two numeric parameters, all obligatory PART GOSBVL RNDAHX * Pick up n2 GONC ERR * no negatives D1=D1+ 16 * shift D1 in readiness for next parameter A=A-1 A * decrement n2 GOC ZERO * if Carry was set, n2 was zero A=A-1 A * decrement n2 again GOC ONE * if Carry was set, n2 was originally one ERR GOVLNG ARGERR * Error for all other values of n2 POP GOSBVL RNDAHX * sub to pop n1 GONC ERR * no negatives A=A+A A * n2 was in bytes, double to get number of nibbles R0=A * save in R0 D1=D1+ 16 * move D1 to collect the string RTN * and return ONE GOSUB POP * 1st part wanted GOSBVL XXHEAD * set R1 to start of string, D1 to end, len in A(A) C=R0 * copy split-point into C(A) ?C>A A * is this > than len? GOYES ERR * then error C=R1 * now copy start address into C(A) A=R0 * and desired len into A(A) C=C-A A * this is the address of new end of string D1=C * set D1 to this P= 0 * prepare for exit through ADHEAD ST=0 0 * no return GOSBVL D=AVMS * probably this line is redundant here, but safer to GOVLNG ADHEAD * include. Now exit (automatically through EXPR) ZERO GOSUB POP * 2nd part wanted GOSBVL REV$ * reverse the string GOSBVL XXHEAD * as above C=R0 * ditto ?C>A A * is split-point > len? GOYES ERR * then error CD1EX * D1 was at end of string - swap into C(A) A=R0 * copy split-point into A(A) C=C+A A * this will be the address for the new end CD1EX * swap this into D1 P= 0 * prepare for ADHEAD ST=1 0 * set for return from ADHEAD GOSBVL D=AVMS GOSBVL ADHEAD * add header and come back GOSBVL REV$ * reverse the string GOVLNG EXPR * and finally exit. * This has been part of my continuing learning process, particularly with * respect to strings. It does have some value for me, however, apart from * that. An example will illustrate that: * A$=PSTR$("AcceptReject",6,TEST(CORR(1,2),N2CORR(M),1))&" H0" * N2CORR is a function I have written to calculate critical values from * student' t distribution and TEST has appeared previously. * Thus if the correlation between variables 1 and 2 exceeds the critical * value, then A$ will read "Accept H0", otherwise, "Reject H0". * Regards, * Jack Elhay.