The following warnings occurred:
Warning [2] Undefined array key 0 - Line: 1677 - File: showthread.php PHP 8.2.31 (Linux)
File Line Function
/inc/class_error.php 157 errorHandler->error
/showthread.php 1677 errorHandler->error_callback
/showthread.php 916 buildtree




Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to manage part of a STRING?
#4
Hello,

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.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)