01-09-2019, 06:07 PM
Hello,
I am looking at string manipulation, particularly in terms of deleting the last character from a string.
My routine is as follows:
The clear keyboard buffer routing is as follows:
And the "delete last character" routine is:
It's the "delete last character" routine that I'm having trouble with. the b$(0 TO LEN(b$)-1) isn't doing what I'm expecting, i.e., if the contents of b$ are:
I want c$ to be:
and therefore be passed back to the b$ string before returning.
Many thanks for any help or advice.
Regards,
Shaun.
I am looking at string manipulation, particularly in terms of deleting the last character from a string.
My routine is as follows:
Code:
3 PRINT "Enter your number"; n$; "c:\>_";
4 LET a$=INKEY$:
IF a$=n$ AND b$<>"" THEN GO TO 9:
END IF
5 IF a$=""
THEN GO TO 4:
END IF
6 IF (CODE a$=8 OR CODE a$=12)
AND LEN(b$)>0 THEN LET a$="":
GO SUB 2000:
GO TO 8:
END IF
7 IF CODE a$<48 OR CODE a$>57
THEN GO TO 4:
END IF
8 LET b$=b$+a$:
PRINT AT 1,4; b$; "_ ":
LET a$=INKEY$:
GO SUB 1000:
GO TO 4
9 REM Rest of programme from here
The clear keyboard buffer routing is as follows:
Code:
1000 IF INKEY$<>"" THEN GO TO 1000:END IF
1001 RETURN
And the "delete last character" routine is:
Code:
2000 LET c$="":
2001 IF LEN(b$)>1
THEN LET c$=b$(0 TO LEN(b$)-1):
END IF
2002 LET b$=c$:
RETURN
It's the "delete last character" routine that I'm having trouble with. the b$(0 TO LEN(b$)-1) isn't doing what I'm expecting, i.e., if the contents of b$ are:
Code:
12345
I want c$ to be:
Code:
1234
and therefore be passed back to the b$ string before returning.
Many thanks for any help or advice.
Regards,
Shaun.