I am trying to write a method to deal with determining a character position using RegEx. I am not one who uses MemoryBlocks in my code routinely. I am vaguely aware of problems that can occur when string characters are not strictly one byte. I do understand the difference between zero and one-based character position. That is not the issue. I go to the Xojo Documentation page for
It says that it " Returns the starting byte offset of the SubExpression given by matchNumber . SubExpressionStartB is zero-based."
The page has a note: To convert this byte offset into a 1-based character position (for use with String functions such as Mid and Left), use this code:
I try and use the information in this note in my own code which is as follows
Var re As New RegEx Var characterPosition As Integer Var theString As String = "SomeExample" Var aRegExMatch As RegExMatch Var m As MemoryBlock m = theString re.SearchPattern = "x" aRegExMatch = re.Search(theString) // re.Search(m) also cause error characterPosition = m.LeftB(aRegExMatch.SubExpressionStartB(0)).Len + 1
I get an error message at the line
characterPosition = m.LeftB(aRegExMatch.SubExpressionStartB(0)).Len + 1
Extension method REALbasic.Len requires a conversion from class MemoryBlock to type String
I thought I was using the code that had been suggested by the documentation but I get an error. Why?