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

  • SEARCH
  • Home
  • 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 7920665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:18:13+00:00 2026-06-03T16:18:13+00:00

I use Scintilla and set it’s encoding to utf8 (and this is the only

  • 0

I use Scintilla and set it’s encoding to utf8 (and this is the only way to make it compatible with Unicode characters, if I understand it correctly). With this set up, when talking about a positions in the text Scintilla means byte positions.

The problem is, I use UnicodeString in the rest of my program, and when I need to select a particular rang in the Scintilla editor, I need to convert from char pos of the UnicodeString to byte pos in a utf8 string that’s corresponding to the UnicodeString. How can I do that easily? Thanks.

PS, when I found ByteToCharIndex I thought it’s what I need, however, according to its document and the result of my testing, it only works If the system uses a multi-byte character system (MBCS).

  • 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-06-03T16:18:15+00:00Added an answer on June 3, 2026 at 4:18 pm

    You should parse UTF8 strings yourself using UTF8 description. I have written a quick UTF8 analog of ByteToCharIndex and tested on cyrillic string:

    function UTF8PosToCharIndex(const S: UTF8String; Index: Integer): Integer;
    var
      I: Integer;
      P: PAnsiChar;
    
    begin
      Result:= 0;
      if (Index <= 0) or (Index > Length(S)) then Exit;
      I:= 1;
      P:= PAnsiChar(S);
      while I <= Index do begin
        if Ord(P^) and $C0 <> $80 then Inc(Result);
        Inc(I);
        Inc(P);
      end;
    end;
    
    const TestStr: UTF8String = 'abФЫВА';
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      ShowMessage(IntToStr(UTF8PosToCharIndex(TestStr, 1))); // a = 1
      ShowMessage(IntToStr(UTF8PosToCharIndex(TestStr, 2))); // b = 2
      ShowMessage(IntToStr(UTF8PosToCharIndex(TestStr, 3))); // Ф = 3
      ShowMessage(IntToStr(UTF8PosToCharIndex(TestStr, 5))); // Ы = 4
      ShowMessage(IntToStr(UTF8PosToCharIndex(TestStr, 7))); // В = 5
    end;
    

    The reverse function is no problem too:

    function CharIndexToUTF8Pos(const S: UTF8String; Index: Integer): Integer;
    var
      P: PAnsiChar;
    
    begin
      Result:= 0;
      P:= PAnsiChar(S);
      while (Result < Length(S)) and (Index > 0) do begin
        Inc(Result);
        if Ord(P^) and $C0 <> $80 then Dec(Index);
        Inc(P);
      end;
      if Index <> 0 then Result:= 0;  // char index not found
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to use Scintilla .NET in a project (I want a good
use this website a lot but first time posting. My program creates a number
USE master GO DECLARE @DbName nvarchar(MAX) SET @DbName = N'DataBase' ALTER DATABASE @DbName SET
I want use the Scintilla controls and the RadControls for Winforms, but I do
Use Eclipse Classic with ADT plugin. Tried to make project from existing example of
I'm trying to use a recent feature of the Scintilla component , which provides
Use trap to capture signals like this: i=-1;while((++i<33)); do trap echo $i >> log.txt
use this code, in the Preferences activity, to know when the reset preference has
I have discovered Scintilla/Notepad++ API this week end. As there is a nice Template
USE [Fk_Test2] GO /****** Object: Table [dbo].[Owners] Script Date: 08/20/2010 16:52:44 ******/ SET ANSI_NULLS

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.