Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6719327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:04:47+00:00 2026-05-26T09:04:47+00:00

Short story : I have an UTF NSString and a byte offset. I want

  • 0

Short story:
I have an UTF NSString and a byte offset. I want to know the character at that byte offset. How can I do?

Below is the long story if you dare:

According this documentation offsets() function returns byte offset inside a column of a term. I have indexed some text and I use that offset to point to a particular section of the text when I display results.

Crucial problem is that using this byte offset I am unable to point the right location of the term. Sometimes it points correctly, sometimes it is 3/4 chars away from right point.

My table is very simple:

CREATE VIRTUAL TABLE t1 USING fts4(file, body, page);

If I do a query such as:

SELECT page, body, offsets(t1) from t1 where body match 'and';

I receive:

...........
502|1 0 427 3
505|1 0 370 3 1 0 1307 3 1 0 1768 3
506|1 0 10 3 1 0 1861 3 1 0 2521 3

...........

As an example if I point to char 427 of body I don’t get the right position of ‘and’ but I jump 2/3 chars away from it. The same if I go to 370 and if I go instead to 10 I get the right position.

Where am I wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:04:47+00:00Added an answer on May 26, 2026 at 9:04 am

    See the Sqlite FTS3 docs and you’ll notice that the offsets and lengths are in bytes not characters.

    You must apply the offset and length before decoding the bytes into a string of characters in order to display the correct offset. The offset coming from Sqlite counts each byte of multibyte characters, whereas you are using that offset to count characters.

    Your indexed text probably has 3 or 4 characters that are two bytes. Hence the off-by-3-or-4 problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long story short, I have a struct (see below) that contains exactly one field:
Long story short, I have a SQL file that I want to import as
Long story short, I have a substantial Python application that, among other things, does
Long story short, I have a long code that uses jQuery. Lots of files,
To cut a long story short I have a C# function that performs a
Long story short, I have two regex patterns. One pattern matches things that I
Ok, long story short I have a Windows service that handles Win32_VolumeChangeEvent and logs
Long story short - I have an editable <div> and I want to clear
Long story short: I have some controller logic that requests a value from the
Long story short -- we have 2 webservers that run a 3rd party asp.net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.