eWON.biz
Knowledge Base

Latest changes
eWON wiki > eWON Support > Knowledge Base > Questions and Answers > INSTR doesn't find chr$(0)

INSTR doesn't find chr$(0)

From $1

Table of contents

 

You cannot search the character null ( chr$(0) ) with INSTR because chr$(0) is the string END delimiter (for the INSTR function, not for the eWON).

Doing

d% = Instr 1, b$, Chr$(00)

is like asking the INSTR to
   search an "empty string" inside the b$ string.
and strangely, it succeeds directly.

If you need to search the character null, you must search it manually inside the string.
Create a string with a null character inside.

b$ = "hello"+chr$(0)+"bonjour"

When you print it, it displays only the   hello
BUT you can see that the length of this b$ is well equal to 13       print len(b$)
And if you search manually with the fonction below, you'll find that  position==6

SearchNull:
  position=0
  For i%= 1 To LEN(B$)
    If B$(i%)=Chr$(0) Then
      position=i%
    Endif
  Next i%
  Print "pos ";position
End