Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • local macro text with line break

    Hi there

    Does anyone know if there is a way to spread the text contents of a local macro across multiple lines?


    Code:
    local lines """First line" "Second line"""
    disp "`lines'"
    The desired result is to display:

    First line
    Second line
    Last edited by tim bradshaw; 29 Nov 2022, 14:36. Reason: Question simplified

  • #2
    Your situation is made somewhat messier by the presence of multiple consecutive double quotes. I'm presuming that you do have to deal with such stuff in your materials. I'm further assuming that the first occurrence of a quote followed by a space demarcates the two lines. Under those conditions, this should do what you want:
    Code:
    local lines """First line" "Second line"""
    local breakpt = strpos(`"`lines'"', `"" "') + 1
    // Extract the content
    local line1 = substr(`"`lines'"', 1, `breakpt')
    local line2 = substr(`"`lines'"', `breakpt' + 1, .)
    // print lines while stripping quotes
    di subinstr(`"`line1'"', `"""', "", .) _newline   subinstr(`"`line2'"', `"""', "", .)
    If you potentially want to deal with, say, more than two lines, or with text that does not have the peculiarity of three quotes in a row, that could be done, but I think we'd need to know what those possible variations are, and what feature of your text will consistently demarcate the chunks you want as separate lines. In your example, chunks are separated by one blank between a pair of double quotes, but I suppose this might not always be the case. Or, perhaps you even have some control over what is used to separate such chunks, which could simplify the situation.

    Comment


    • #3
      You could do this like so:

      . local lines """First line" _n "Second line"""

      . disp "`lines'"
      First line
      Second line


      Comment


      • #4
        Nice approach from Matthew Hall ; I just *assumed* all the apparently extraneous quotes had to be cleaned up. I guess they're a feature rather than a bug.

        Comment


        • #5
          That's really helpful, thanks so much!

          Comment


          • #6
            tim bradshaw All of this can work with fewer quotes all around, both in the local macro and the display command.

            If you did either
            Code:
            local lines `""First line" _n "Second line""'
            or even
            Code:
            local lines ""First line" _n "Second line""
            then with either, typing just
            Code:
            dis `lines'
            will produce
            Code:
            First line
            Second line
            But if the quotes are for some reason, a feature not a bug, as #4 notes, then #3 probably works best.

            Comment

            Working...
            X