Searching in binary strings with the nul character

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

Searching in binary strings with the nul character

Post by newbieforever »

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
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Searching in binary strings with the nul character

Post by fxm »

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: 117
Joined: Jun 21, 2018 11:14

Re: Searching in binary strings with the nul character

Post by newbieforever »

Fast, precise, targeted, not digressive, helpful!

You are a schatz, fxm!
Post Reply