Page 1 of 1

How to get first charater number of a line

Posted: Tue Aug 11, 2009 5:22 pm
by ale870
Hello,

I have the following text inside a text field (multiline):

Code: Select all

This is first line
and this is the second line
instead, this is the third line!
Well, first character of the second line is the character number 20 (19+return).

Well, I need to know that number "20" when the user select a word in a line.
For example, if the user select/highlight (with the mouse for example) the word "second" (in the second row), I need to get the char position of the first char in the row (in this case I need to get the position of char "a" inside the word "and").

Thank you for your help!

Posted: Tue Aug 11, 2009 5:32 pm
by ale870
Just to explain what I'm doing (maybe you could give me a better idea).

I need to duplicate the selected text just below the position of the selected text.
See this example:

Code: Select all

1> ORIGINAL LINE text selected MORE TEXT
2>                        text selected
In the first line, the user selected "text selected". When I duplicate that text, I need to put it just below the original text - see line 2.

Posted: Tue Aug 11, 2009 8:10 pm
by ale870
Hello,

I solved writing this code (maybe someone could give me better solutions).
I hope this code could help to someone!

Code: Select all

local myAbsCharStartNum, myAbsCharEndNum, mySelectedLineNum, mySelectedText
         
         put word 2 of the selectedChunk into myAbsCharStartNum
         put word 4 of the selectedChunk into myAbsCharEndNum
         
         put word 2 of the selectedLine into mySelectedLineNum
         
         put the selectedText into mySelectedText
         
         // --
         
         local myCharOffsetNum
         
         select char 1 of line mySelectedLineNum of field "fldMain"
         
         put myAbsCharStartNum - (word 2 of the selectedChunk) + 1 into myCharOffsetNum
         put "" into message
         
         put mySelectedText into char myCharOffsetNum to myCharOffsetNum + len(mySelectedText) - 1 of line (mySelectedLineNum+1) of field "fldMain"
         
         // --
         
         select char myCharOffsetNum to myCharOffsetNum + len(mySelectedText) - 1 of line (mySelectedLineNum+1) of field "fldMain"
         

         
Please note: field "fldMain" is the field containing text to be duplicated.