MathGroup Archive 2004

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

Search the Archive

Re: colored alphabet for string output

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.


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

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