0

I want to make my output look something like this:

First line of text Second line of text

Third line of text Fourth line of text ...

I'm having the hardest time figuring out how to do this.

I have an array of strings, and they're pretty close to the same length. Sadly, they're many (in excess of 50), and to display them as a menu is rather ungainly.

I'd also be very happy just splitting it down a third, after a specified number, and displaying the rest in a second and third column.

1 26 51

. . .

. . .

25 50 * Thanks for your help.

4
  • 1
    What have you tried, and how has what you've tried failed? Ideally, you should provide a Minimal, Complete, and Verifiable Example of what you've tried, and include specific information on how it failed, with error messages and/or erroneous output. SO is not a code-writing service; the best questions are those which provide useful information so that those who answer can guide you to devising your own correct answer. See How to Ask a Good Question. Commented Aug 28, 2017 at 18:04
  • I have no example to give, other than what I gave. I have no error codes, none are given (because there is no error, it's just not done). Commented Aug 28, 2017 at 18:18
  • Show part of what you wrote... Commented Aug 28, 2017 at 18:22
  • No. What I wrote works fine, I want to do it a different way. I just want it in columns. Why is this hard? I want to output into columns. I don't know how to do that, I am asking how to do that. It really doesn't matter what I have, as I will adapt it to how it's done. Commented Aug 28, 2017 at 18:47

1 Answer 1

3

Format-Wide can format your output the way you describe, unfortunately it doesn't accept a raw string array as input.

If you have an array of strings, you can use Select-Object to create pipeline objects you can feed to Format-Wide:

$linesOfText = @(
  "First line of text",
  "Second line of text",
  "Third line of text",
  "Fourth line of text"
)

$linesOfText |Select-Object @{Name='String';Expression={$_}}|Format-Wide String -Column 2

You should see the output in 2 columns, like:

First line of text                             Second line of text
Third line of text                             Fourth line of text
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! That's what I needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.