xboxscene.org forums

Author Topic: How Do I Find The Size Of A String  (Read 86 times)

xman954

  • Archived User
  • Hero Member
  • *
  • Posts: 835
How Do I Find The Size Of A String
« on: October 17, 2005, 12:22:00 AM »

CODE

                xor          ebx,ebx  ; start at 0
                xor          edx,edx
                mov          ecx,79  ; set max size
nx_chr.        add          ebx,byte 01   ; inc it   
                mov          dl,byte [eax+ebx]
                loopnz       nx_chr.
                mov          [handle_save],ebx
the string is 02Fh long, but ebx is 04Fh
is there any other way to do this (im sure there is)
Logged

dus

  • Archived User
  • Newbie
  • *
  • Posts: 16
How Do I Find The Size Of A String
« Reply #1 on: October 17, 2005, 04:02:00 AM »

rolleyes.gif

You should have two end conditions, one when ecx is zero (which you have) and one when the zero flag is set. Try a cmp or similar in the loop to check for the null byte .

CODE

          xor       ebx,ebx
          mov       ecx, 79
next:    cmp       byte [eax+ebx],0
          inc       ebx
          loopnz    next
          mov       [str_length],ebx


Now this also counts the null char at the end. I leave it as an exercise to modify it. smile.gif
Logged