How to convert the byte offset from sqlite FTS query into a character offset in java

Viewed 587

I have a problem where I am searching my FTS tables in android and I get returned a byte offset for the result :

col     termno      byteoffset      size
1       0           111             4

However problem is, when using cursor.getString(colNo) it gives me a UTF-16 string after which I am unable to tally up which character of the text is the start/end of the match.

Its a similar problem to : Detect character position in an UTF NSString from a byte offset(was SQLite offsets() and encoding problem)

However I cannot fathom the solution in the question. So how can I accurately know the character offsets in my string (for highlight) after I know the byte offsets?

1 Answers
Related