Searching in binary strings with the nul character

New to FreeBASIC? Post your questions here.
newbieforever
Posts: 84
Joined: Jun 21, 2018 11:14

Searching in binary strings with the nul character

Postby newbieforever » Jun 29, 2018 20:32

Another aspect of my problem...

This is my simplified setting (just as example!):

The text file Text.txt containing the string 'abcdefgh' was saved as unicode.

A string is generated by reading from the binary file Text.txt (st = Input(100, #1)). The string looks like this: 'a.b.c.d.e.f.g.h', where '.' represents the nul character (NUL).

Now I would like to search in this binary string, e.g. for 'fg'. This means that I have to search for the character sequence f, NUL, g.

How this search can be done with instr?
fxm
Posts: 8298
Joined: Apr 22, 2009 12:46
Location: Paris (suburb), FRANCE

Re: Searching in binary strings with the nul character

Postby fxm » Jun 29, 2018 20:56

Code: Select all

Dim As String s = "a" & Chr(0) & "b" & Chr(0) & "c" & Chr(0) & "d" & Chr(0) & "e" & Chr(0) & "f" & Chr(0) & "g" & Chr(0) & "h"
Dim As String subs = "f" & Chr(0) & "g"

Print Instr(s, subs)
newbieforever
Posts: 84
Joined: Jun 21, 2018 11:14

Re: Searching in binary strings with the nul character

Postby newbieforever » Jun 29, 2018 21:00

Fast, precise, targeted, not digressive, helpful!

You are a schatz, fxm!

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 2 guests