Re: [Vala] Convert from byte to character offset in string



On Wed, Jul 14, 2010 at 08:45:54PM +0930, James Moschou wrote:
I'm sorry I don't see how this is what I want. My problem is that I am
implementing a text view with a cursor that works in characters.
However I use Pango to figure out where to draw the cursor, and Pango
works in bytes, so I need to convert between the two.

I reckon I could do:
    byte_offset = mystring.substring(0, character_offset).to_utf8().length;

Try:
size_t byte_offset = (void*)mystring.offset(character_offset)-(void*)mystring;

-- 
http://www.debian.org - The Universal Operating System

Attachment: signature.asc
Description: Digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]