$CPU 8086 ' make compatible with XT systems $LIB ALL OFF ' turn off all PowerBASIC libraries $ERROR ALL OFF ' turn off all PowerBASIC error checking $OPTIMIZE SIZE ' optimize for smaller code $COMPILE UNIT ' compile to a UNIT (.PBU) '$COMPILE EXE ' compile to a UNIT (.PBU) DEFINT A-Z ' Required for all numeric functions, forces PB to not ' include floating point in UNIT (makes it smaller) '/*------------------------------------------------------------------*/ $CODE SEG "MLIB5" '/*------------------------------------------------------------------*/ ' INSERTSTR(NEW,TARGET,N,LENGTH,PAD) ' Insert String. ' Inserts the string NEW, padded to length LENGTH, into string ' TARGET after the Nth character. LENGTH and N must be positive ' numbers. If N is greater than the length of the TARGET string, ' padding is added to the end of TARGET to make its length equal ' to N. If N = 0 then string NEW is inserted before TARGET. ' EXAMPLE: PRINT INSERTSTR(" ","abcdef",3,0," ") = 'abc def' ' PRINT INSERTSTR("123","abc",5,6," ") = 'abc 123 ' ' PRINT INSERTSTR("123","abc",5,6,"+") = 'abc++123+++' ' PRINT INSERTSTR("123","abc",0,0," ") = '123abc' ' PRINT INSERTSTR("123","abc",0,5,"-") = '123--abc' '/*------------------------------------------------------------------*/ FUNCTION INSERTSTR(BYVAL NW AS STRING, BYVAL TARGET AS STRING, BYVAL N AS INTEGER, BYVAL L AS INTEGER, BYVAL PAD AS STRING) PUBLIC AS STRING LNEW = LEN(NW) LTARGET = LEN(TARGET) IF N > LTARGET THEN TARGET = TARGET + STRING$(N-LTARGET,PAD) IF L > LNEW THEN NW = NW + STRING$(L-LNEW,PAD) LNEW = LEN(NW) LTARGET = LEN(TARGET) IF N = 0 THEN XRET$ = NW + TARGET IF N > 0 THEN IF N = LTARGET THEN TL$ = TARGET TR$ = "" ELSE TL$ = LEFT$(TARGET,N) IF N < LTARGET THEN TR$ = RIGHT$(TARGET,LTARGET-N) ELSE TR$ = "" END IF END IF XRET$ = TL$ + NW + TR$ END IF FUNCTION = XRET$ END FUNCTION '/*------------------------------------------------------------------*/ ' CLS ' PRINT INSERTSTR(" ","abcdef",3,0," ") ' PRINT INSERTSTR("123","abc",5,6," ") ' PRINT INSERTSTR("123","abc",5,6,"+") ' PRINT INSERTSTR("123","abc",0,0," ") ' PRINT INSERTSTR("123","abc",0,5,"-") ' INPUT Z