set the textStyle to not bold

Beat Cornaz B.Cornaz at gmx.net
Sat Oct 3 12:50:35 EDT 2009


 >Devin wrote :
 >repeat with i = 1 to the number of words in fld "thefield"
 >   get the textStyle of word i of fld "thefield"
 >   if it contains "bold" then
 >    replace "bold" with empty in it
 >     replace ",bold" with empty in it
 >     replace "bold," with empty in it
 >     set the textStyle of word i of fld "thefield" to it
 >   end if
 >end repeat

Thanks Devin, it works partly.
  First I added 2 lines which actually do the same as yours intended,  
but did not work (maybe I should have set the wholematches to true).
Anyway, the principle works in so far that sometimes I get 'mixed' as  
TextStyle (in case of 'link' text). I also need to come up with  
something for the empty spaces between the words. Sometimes the 'box'  
style (which I actually use instead of bold) does not get removed  
between words.

repeat with i = 1 to the number of words in fld "A"
    get the textStyle of word i of fld "A"
    if it contains "bold" then
      replace "bold" with empty in it
      if char 1 of it = comma then delete char 1 of it
       if char -1 of it = comma then delete char -1 of it
      set the textStyle of word i of fld "A" to it
    end if
end repeat

 >Paul wrote :

I replaced 'bold' with 'box' as it also shows better if it has not  
been removed from the spaces between words

 >repeat with i = 1 to the number of words in fld "A"
 > get the textStyle of word i of fld "A"
 > if it contains "box" then
 >   replace "box" with "plain" in it
 >   set the textStyle of word i of fld "A" to it
 > end if
 >end repeat

Your script works as well as Devin's and also has the same  
'shortcoming' of not removing the style between words.

I tried it out with checking and setting on character level. That  
works for 'bold', but it does NOT work for 'box'. The reason is that  
the textStyle returned from a char which is box and bold and  
underline is only box. So replacing 'box' with plain throws away the  
bold and underline as well.

The solution Devin offered is better in this respect. By replacing  
the 'box' with empty leaves the other style settings untouched  
(although they do not show up in the variable it).

So for the moment I will go for Devin's solution, but on a character  
level.

Thanks,

Beat


More information about the use-livecode mailing list