How to get first charater number of a line

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

How to get first charater number of a line

Post by ale870 » Tue Aug 11, 2009 5:22 pm

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!

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Post by ale870 » Tue Aug 11, 2009 5:32 pm

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.

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Post by ale870 » Tue Aug 11, 2009 8:10 pm

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.

Post Reply