MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: colored alphabet for string output

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48207] Re: [mg48188] colored alphabet for string output
  • From: Oleksandr Pavlyk <pavlyk at phys.psu.edu>
  • Date: Tue, 18 May 2004 04:16:12 -0400 (EDT)
  • Organization: Penn State University; Department of Physics
  • References: <200405170721.DAA29573@smc.vnet.net>
  • Reply-to: pavlyk at phys.psu.edu
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Curt,

First you split your strings into characters,
using Characters["string"], then you treat
each character the way you intended to do it,
converting a list of characters into a list
of StyleBoxes, and then you display them together
wrapping them with RowBox. The code follows.

Sasha

In[2]:=
myList = {"abcdefg",
     "hijklmn", "prstuv"};
In[28]:=
colorFunc[x_] :=
   Hue[Sequence @@
     N[(ToCharacterCode[x] -
        ToCharacterCode["a"])/
       (ToCharacterCode["z"] -
        ToCharacterCode["a"])]]
In[31]:=
DisplayForm[RowBox[
    (StyleBox[#1, FontColor ->
        colorFunc[#1]] & ) /@
     Flatten[Characters /@
       myList]]]

Curt Fischer wrote:
> Dear Group:
> 
> I have a long list of alphabetic strings.  I would like to ouput this list,
> with each of the letters of the string colored differently.  How could I do
> this?
> 
> For example:
> 
> myList = {"abcdefg","hijklmn","prstuv"};
> 
> myList/.{x_String -> StringReplace[x, "a" -> StyleForm["a", FontColor ->
> Red]]}
> 
> I was thinking to hodgepodge together statements like this, but it doesn't
> work because StringReplace requires objects with head String, and my attempt
> has an object with head StyleForm.
> 
> Any advice?


  • Prev by Date: Re: Precision of output
  • Next by Date: RE: Selecting by first element of each list
  • Previous by thread: colored alphabet for string output
  • Next by thread: Re: colored alphabet for string output