Empty string: Difference between revisions

(add gwbasic)
Line 3,040:
");
]</lang>
 
=={{header|Z80 Assembly}}==
{{trans|6502 Assembly}}
An empty string is just a null terminator with no text in front.
<lang z80>EmptyString:
byte 0</lang>
 
Checking if a string is empty is simple, just count the number of characters before you reach the terminator. If that count equals zero, the string is empty. Otherwise, the string is not empty.
 
<lang z80>ld hl,MyString
 
GetStringLength:
ld b,0 ;zero the length counter
loop_getStringLength:
ld a,(hl)
or a ;compare A to zero
ret z ;exit if zero
 
inc hl ;next char
inc b ;add 1 to length counter
jr loop_getStringLength
 
ld b,a
or a
jr z,StringIsEmpty</lang>
 
</lang>
 
=={{header|zkl}}==
1,489

edits