Jump to content

String length: Difference between revisions

Line 3,645:
===Character Length===
<lang yorick>strlen("Hello, world!")</lang>
 
=={{header|Z80 Assembly}}==
 
The majority of Z80-based hardware predates Unicode so only byte length will be demonstrated for now.
 
===Byte Length===
Code is called as a subroutine, i.e. <code>CALL getStringLength</code>
<lang z80>; input: HL - pointer to the 0th char of a string.
; outputs length to B. HL will point to the last character in the string just before the terminator.
; length is one-indexed and does not include the terminator. A null string will return 0 in B.
 
; "Terminator" is a label for a constant that can be configured in the source code. My code uses 0.
; Sample Usage:
; ld hl,MyString
; call GetStringLength
 
GetStringLength:
ld b,0
loop_getStringLength:
ld a,(hl) ;load the next char
cp Terminator ;is it the terminator?
ret z ;if so, exit.
inc hl ;next char
inc b ;increment the byte count
jr loop_getStringLength</lang>
 
=={{header|zkl}}==
1,489

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.