Hi Pixelink, you are right, your issue relates to 'end of line markers'. In Unix (ie Linux, Mac) we have but one character reserved to mark the end of a line. But Windows (and DOS), for reasons only know to a certain Mr Gates, we get two characters, a Carrage Return and a Line Feed. So, if you look into the KMemo1.Text you would see -
one<CR><LF>two<CR><LF>
Thats 10 characters in total (Gets more complicated using UTF8 but consistent).
PosEx will return 6 if you search for 'two' (but only 5 on Unix).
KMemo's char count always (sensibly) counts 1 char for a ParagraphBlock so your code will work fine under Linux (it does, I tested it) but I bet you are using windows ?
The code fragment from the wiki (my code!) counts how many addition characters have been inserted at the point we are interested in, subtracts that number from what PosEx() tells us, converting it into a number suitable to use as a KMemo character index.
I am afraid you really do need to use that extra code, no getting around it.
EDIT : KMemo is a great tool actually, I use it in tomboy-ng notes. I initially tried RichMemo but it is missing a number of functions. I have logged some but reports and patches, some used. Development is slow, I suspect skalogryz has his hands full getting Cocoa up to speed, important work !
On the other hand, TK will apply patches to KControls (inc KMemo) if you send them in. He is not willing to further develop it himself. And right now, its works a treat.
Davo