' DIVIDE.BAS
' This program divides a string into three parts.

CONST BLANK$ = " "                    ' declare string constant
char$ = ""                            ' initialize variables
charCount% = 1
nameCount% = 0

CLS                                   ' clear screen

PRINT "Enter name in the following format:  First Middle Last"
INPUT "Name:  ", fullName$            ' get 3-part name from user
nameLength% = LEN(fullName$)          ' determine length of name

' loop until the entire three-part string has been stepped through

DO WHILE (charCount% <> nameLength% + 1)

'   read characters one at a time until a blank or end of string
'     is encountered; assign characters to name$ variable

    DO WHILE (char$ <> BLANK$) AND (charCount% <> (nameLength% + 1))
        char$ = MID$(fullName$, charCount%, 1)
        name$ = name$ + char$
        charCount% = charCount% + 1   ' track number of character read
    LOOP

    char$ = ""                        ' reset char$
    nameCount% = nameCount% + 1       ' increment nameCount%
   
    SELECT CASE nameCount%            ' assign string to name variables
        CASE 1                        '   based on value of nameCount%
            firstName$ = name$
        CASE 2
            middleName$ = name$
        CASE 3
            lastName$ = name$
    END SELECT
    name$ = ""                        ' reset name$
LOOP

PRINT
PRINT "Results of separation process:"
PRINT
PRINT "First name is "; firstName$    ' display results
PRINT "Middle name is "; middleName$
PRINT "Last name is "; lastName$

