array elements appear on a single line in a here-string

Welcome Forums General PowerShell Q&A array elements appear on a single line in a here-string

Viewing 3 reply threads
  • Author
    Posts
    • #280200
      Participant
      Topics: 34
      Replies: 65
      Points: 237
      Rank: Participant

      how do i get the elements of the two arrays below to appear on separate lines in the here-string, instead of all on one line?

      array1 says
      this
      that
      the other

      array2 says
      one
      two
      three

      herestring says

      array1 says

      this that the other

      array2 says

      one two three

    • #280215
      Participant
      Topics: 34
      Replies: 65
      Points: 237
      Rank: Participant

      turning the array into a string with join backtick n also doesn’t workdoes work after all.

       

       

    • #280260
      Senior Moderator
      Topics: 9
      Replies: 1449
      Points: 5,426
      Helping Hand
      Rank: Community MVP

      arrrays when wrapped in double quotes will automatically gets joined by $OFS, which is an automatic variable which defaults to ‘ ‘.

    • #280293
      Participant
      Topics: 17
      Replies: 1951
      Points: 3,988
      Helping Hand
      Rank: Community Hero

      One method:

      Would also mention this appears you are writing a message for email, which then you should be looking at HTML (ConvertTo-HTML) and not plain text in a here string.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.