So if my memory block looked like this (hex bytes shown):
Code: Select all
41 42 43 00 44 45 46 00 47 48 49 ; ABC DEF GHI
Code: Select all
Debug FindStringInMemory(memory,"DEF",1)
Code: Select all
41 42 43 00 44 45 46 00 47 48 49 ; ABC DEF GHI
Code: Select all
Debug FindStringInMemory(memory,"DEF",1)
How would the command know when to stop searching if it continued past a 0-byte? Wouldn't that cause IMA's each time the string was not found?UserOfPure wrote:Would be GREAT if there was a command to find a string in a memory block (perhaps called "FindStringInMemory"?), with the result being the offset from the start of the memory block. It would work just like FindString but without dying when it finds a 0-byte.
So if my memory block looked like this (hex bytes shown):
Then the following command would return 5 because "DEF" is at offset 5:Code: Select all
41 42 43 00 44 45 46 00 47 48 49 ; ABC DEF GHI
Code: Select all
Debug FindStringInMemory(memory,"DEF",1)
Since every allocated memory block has a set size, then obviously the search stops at the end of it. An optional "length" parameter could be used, too.Demivec wrote:How would the command know when to stop searching
Code: Select all
Procedure FindStringInMemory(String.s, Memory, MemoryLength)
Protected L = Len(String)
For I = 0 To MemoryLength-L
If CompareMemory(@String, Memory+I, L)
ProcedureReturn I+1
EndIf
Next
EndProcedure
Code: Select all
Memory.s = "ABC DEF GHI"
Debug FindStringInMemory("DEF", @Memory, Len(Memory))
All memory are equally good memory. It really doesn't matter whether your memory area is part of a string or not. I just used a string in the example. The first parameter is always a string, which is what you asked for.Trond, but is that just for searching the memory of strings?