UCASE$ / LCASE$

Syntax

Syntax: UCASE$(string$)   LCASE$(string$)
Source: pb_cg_emit_string_builtin_to_heap_temp (pb_codegen.c:3397)

Description

Converts all alphabetic characters in string$ to uppercase or lowercase respectively.

The conversion operates on the ASCII range [A-Za-z] only. Characters outside this range (digits, punctuation, symbols, extended ASCII, or Unicode) pass through unchanged. The original string is not modified.

Case conversion is essential for case-insensitive comparisons, normalizing user input (e.g., command keywords), formatting display text, and preparing strings for sorting or hashing where case should be ignored.

Parameters

ParameterDescription
string$The STRING expression to convert. Can be a literal, variable, or any string expression. Original is unchanged.

Return Value

A new STRING with all alphabetic characters converted to the target case.

Example

FUNCTION PBMAIN() AS LONG
    LOCAL original$, result$ AS STRING
    
    original$ = "Hello World 123!"
    
    ' Convert to uppercase
    result$ = UCASE$(original$)   ' result$ = "HELLO WORLD 123!"
    PRINT "Uppercase: "; result$
    
    ' Convert to lowercase
    result$ = LCASE$(original$)   ' result$ = "hello world 123!"
    PRINT "Lowercase: "; result$
    
    ' Non-alpha characters are unchanged
    PRINT "Digits unchanged: 123!"
    
    ' Case-insensitive comparison pattern
    original$ = "PowerBASIC"
    IF UCASE$(original$) = "POWERBASIC" THEN
        PRINT "Match (case-insensitive)"
    END IF
    
    ' Practical: normalize command input
    original$ = "  QuIt  "
    result$ = TRIM$(UCASE$(original$))  ' result$ = "QUIT"
    IF result$ = "QUIT" THEN
        PRINT "Exit command recognized"
    END IF
    
    ' Practical: proper case formatting
    original$ = "john smith"
    result$ = UCASE$(LEFT$(original$, 1)) + _
              LCASE$(MID$(original$, 2))  ' result$ = "John smith"
    PRINT "Proper case: "; result$
    
    FUNCTION = 0
END FUNCTION

Generated Assembly

Source: pb_cg_emit_string_builtin_to_heap_temp (pb_codegen.c:3397)
; Copy source to heap, iterate byte-by-byte:
; UCASE: if 'a' <= byte <= 'z': sub byte, 32
; LCASE: if 'A' <= byte <= 'Z': add byte, 32
; Then point descriptor to result

Notes