The code does a similar job as a 'robust' input routine. The purpose is to accept user keypresses, then convert ascii characters into proper data consisting of words and numbers.
You must ensure that your routine misses no piece of data, and furthermore it cannot be made to crash by any unexpected keypress (accidental or deliberate).
Obviously you need to tailor the routines to handle your particular needs. I guess you use a different programming language than BASIC.
As an example...
To examine one or more characters within a string, BASIC has these command keywords:
MID$(a$,x,y)
MID$(a$,b$)
LEFT$(a$,x)
RIGHT$(a$,x)