Character Position Of Word in Field

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
warrenk
Posts: 110
Joined: Sun Sep 21, 2008 5:39 am

Character Position Of Word in Field

Post by warrenk » Fri Oct 01, 2010 6:15 pm

What would be the easiest way to get the character positions of a word in a field?

ie (pseudo code)
get beginning and/or end character postion of word x in field "My Text"

Thanks for any help!
Warren

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Character Position Of Word in Field

Post by jmburnod » Fri Oct 01, 2010 10:16 pm

Hi,

You can try this script.
startEndWord return the position of the fist char and the position of the last char of the word

Code: Select all

on mouseUp
   put startEndWordInFld(TheWord,fld 1)
end mouseUp

function startEndWordInFld pWord,pText 
   put empty into rStartEndWordInFld
   put the num of chars of pWord into nbc
   put offset(pWord,pText) into startW
   put startW+nbc-1 into endW
   put "char"&&startW&&"to"&&endW into rStartEndWordInFld
   return rStartEndWordInFld
end startEndWordInFld

Best

Jean-Marc
https://alternatic.ch

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”