Page 1 of 1

Select a word from end of the line

Posted: Thu Jun 25, 2015 8:00 am
by shalu
I am beginner in Livecode, I am looking for the code of select the word from end of the line and when it's find comma then selected content is assigned to a variable. :roll: :oops:

Re: Select a word from end of the line

Posted: Thu Jun 25, 2015 8:22 am
by Dixie
I think this is what you want to do...

Code: Select all

on mouseUp
   put "The clouds are moving quickly across the sky" into theWords
   put the last word of theWords & comma after theData
   put theData
end mouseUp

Re: Select a word from end of the line

Posted: Thu Jun 25, 2015 10:42 am
by shalu
it's not working, my requirement, I have a Scrolling field containing text (eg: ss1-ss CR sd--sd CR sss---dsd) here CR means ss1-ss e.t.c are separate lines. I want separate these words and store words in separate variable. I am using the following code, it's only work first condition (ss1-ss) but it's not working in sd--sd (here separated by ndash) also sss---dsd (mdash).

Code: Select all

command selectedtext1
   put the selectedText into selectvari
   put "-" into dash
   put "--" into ndash
   put "----"into ndash 
   if  selectvari contains dash then
      split selectvari by dash 
      put selectvari[1] into newvari1
      put selectvari[2] into newvari2
      answer newvari1 
      answer newvari2
   else if selectvari contains ndash then
      split selectvari by ndash
      put selectvari[1] into newvari3
      put selectvari[2] into newvari4
      answer newvari3 
            answer newvari4
   else  if selectvari contains mdash then
      split selectvari by mdash
      put selectvari[1] into newvari5
      put selectvari[2] into newvari6
      answer newvari5
      answer newvari6
   else
      beep
   end if
end selectedtext1

Re: Select a word from end of the line

Posted: Thu Jun 25, 2015 10:53 am
by Dixie
Why did you not explain your problem at length, as you have attempted to do in your second post, when you first created the thread !!? ...

Re: Select a word from end of the line

Posted: Thu Jun 25, 2015 2:10 pm
by dunbarx
Without going too deeply into your handler, I think that:

Code: Select all

 put "--" into ndash
put "----"into ndash 
seems unlikely to help you. Maybe:

Code: Select all

 put "--" into ndash
put "----"into nndash 
Craig Newman

Re: Select a word from end of the line

Posted: Thu Jun 25, 2015 8:43 pm
by jacque
I'd do this:

Code: Select all

command selectedtext1
  put the selectedText into selectvari
  repeat for each item i in "-,–,-"
    if  selectvari contains i then
      set the itemdel to i
      put item 1 of selectvari into newvari1
      put item 2 of selectvari into newvari2
      answer newvari1
      answer newvari2
      exit selectedtext1
    end if
  end repeat
  beep
end selectedtext1
The characters between the quotes are the actual hyphen, ndash and mdash, though they look similar here in the post.