Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #12460 > unrolled thread

Re: How Can I Make A String Variable With Styled Text?

Started byBob Hanlon <hanlonr357@gmail.com>
First post2012-11-25 10:00 +0000
Last post2012-11-25 10:00 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How Can I Make A String Variable With Styled Text? Bob Hanlon <hanlonr357@gmail.com> - 2012-11-25 10:00 +0000

#12460 — Re: How Can I Make A String Variable With Styled Text?

FromBob Hanlon <hanlonr357@gmail.com>
Date2012-11-25 10:00 +0000
SubjectRe: How Can I Make A String Variable With Styled Text?
Message-ID<k8sq79$omp$1@smc.vnet.net>
If you apply a style then the resultant will not be a string.

$Post =.

boldFirstSentence[str_String] :=
  Module[
   {pos = StringPosition[str, "." | "!" | "?"], p},
   If [Length[pos] == 0, str,
    p = pos[[1, 1]];
    StringForm["``" <> StringDrop[str, p],
     Style[StringTake[str, p], Bold]]]];

myString = "This is boldface.  The rest is not.";

boldFirstSentence[myString]

StringForm["``  The rest is not.",
Style["This is boldface.", Bold]]

Or you can have it applied automatically to all string output

$Post = If[Head[#] === String, boldFirstSentence[#], #] &;

myString

StringForm["``  The rest is not.",
Style["This is boldface.", Bold]]


Bob Hanlon


On Sat, Nov 24, 2012 at 2:29 AM, Gregory Lypny
<gregory.lypny@videotron.ca> wrote:
> Hello everyone,
>
> I have a string variable
>
> myString = "This is boldface.  The rest is not."
>
> When I execute myString, I want the first sentence to appear in bold type.  Selecting the sentence and formatting it as bold when I create the string does not work.  StringForm will do the trick, as in
>
>         myString = StringForm["`` The rest is not.", Style["This is boldface", Bold]]
>
> but, of course, the Head of myString will no longer be String.  Is there any other way to do this?
>
> Gregory
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web