Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Is there an easy way to wrap text

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-23-2008   #1 (permalink)
RickB
Guest


 

Is there an easy way to wrap text

I'm programatically building some text. I end up with a string of
about
1000 - 5000 characters.
When I'm done I need to break it into an array of strings, each with
80
chars or less. This is supposed to be readable when I'm done so I
can't
just chop it into 80 char sections.
Is there a function that does this or at least one that makes it easy?

Thanks

My System SpecsSystem Spec
Old 05-23-2008   #2 (permalink)
Marco Shaw [MVP]
Guest


 

Re: Is there an easy way to wrap text

RickB wrote:
Quote:

> I'm programatically building some text. I end up with a string of
> about
> 1000 - 5000 characters.
> When I'm done I need to break it into an array of strings, each with
> 80
> chars or less. This is supposed to be readable when I'm done so I
> can't
> just chop it into 80 char sections.
> Is there a function that does this or at least one that makes it easy?
>
> Thanks
How about this:
http://www.microsoft.com/technet/scr.../apssol06.mspx

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 05-23-2008   #3 (permalink)
RichS [MVP]
Guest


 

RE: Is there an easy way to wrap text

Lets start by building our string

PS> $str = "abcd" + "," + "efgh" + "," + "ijkl" + "," + "mnopq" + "," +
"rstu" + "," + "vwxyz"
PS> $str
abcd,efgh,ijkl,mnopq,rstu,vwxyz

I'm using , as a delimiter between the sections i.e. I will be splitting
this string at the commas. The delimter could be any character(s) even a
space - as long as you know it form part of any of your data sections

We can then create an array by using the Spilt() method giving the delimiter
you want to use

PS> $array = $str.Split(",")
PS> $array
abcd
efgh
ijkl
mnopq
rstu
vwxyz

If you have the PowerShell V2 CTP you could use the -split operator instead

PS> $array2 = $str -split ","
PS> $array2
abcd
efgh
ijkl
mnopq
rstu
vwxyz



--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"RickB" wrote:
Quote:

> I'm programatically building some text. I end up with a string of
> about
> 1000 - 5000 characters.
> When I'm done I need to break it into an array of strings, each with
> 80
> chars or less. This is supposed to be readable when I'm done so I
> can't
> just chop it into 80 char sections.
> Is there a function that does this or at least one that makes it easy?
>
> Thanks
>
My System SpecsSystem Spec
Old 05-23-2008   #4 (permalink)
RichS [MVP]
Guest


 

RE: Is there an easy way to wrap text

Thinking about there is another alternative.

Create an empty array

PS> $array3 = @()

In your program add the text directly into the array e.g.

PS> $array3 += "abcd"
PS> $array3 += "efgh"
PS> $array3 += "ijkl"
PS> $array3 += "mnopq"
PS> $array3 += "rstu"
PS> $array3 += "vwxyz"

Then its alreday for you and you saving the string building and splitting
effort

PS> $array3
abcd
efgh
ijkl
mnopq
rstu
vwxyz
PS>
--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"RichS [MVP]" wrote:
Quote:

> Lets start by building our string
>
> PS> $str = "abcd" + "," + "efgh" + "," + "ijkl" + "," + "mnopq" + "," +
> "rstu" + "," + "vwxyz"
> PS> $str
> abcd,efgh,ijkl,mnopq,rstu,vwxyz
>
> I'm using , as a delimiter between the sections i.e. I will be splitting
> this string at the commas. The delimter could be any character(s) even a
> space - as long as you know it form part of any of your data sections
>
> We can then create an array by using the Spilt() method giving the delimiter
> you want to use
>
> PS> $array = $str.Split(",")
> PS> $array
> abcd
> efgh
> ijkl
> mnopq
> rstu
> vwxyz
>
> If you have the PowerShell V2 CTP you could use the -split operator instead
>
> PS> $array2 = $str -split ","
> PS> $array2
> abcd
> efgh
> ijkl
> mnopq
> rstu
> vwxyz
>
>
>
> --
> Richard Siddaway
> All scripts are supplied "as is" and with no warranty
> PowerShell MVP
> Blog: http://richardsiddaway.spaces.live.com/
> PowerShell User Group: http://www.get-psuguk.org.uk
>
>
> "RickB" wrote:
>
Quote:

> > I'm programatically building some text. I end up with a string of
> > about
> > 1000 - 5000 characters.
> > When I'm done I need to break it into an array of strings, each with
> > 80
> > chars or less. This is supposed to be readable when I'm done so I
> > can't
> > just chop it into 80 char sections.
> > Is there a function that does this or at least one that makes it easy?
> >
> > Thanks
> >
My System SpecsSystem Spec
Old 05-23-2008   #5 (permalink)
RickB
Guest


 

Re: Is there an easy way to wrap text

On May 23, 1:21*pm, "Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com>
wrote:
Quote:

> RickB wrote:
Quote:

> > I'm programatically building some text. *I end up with a string of
> > about
> > 1000 - 5000 characters.
> > When I'm done I need to break it into an array of strings, each with
> > 80
> > chars or less. *This is supposed to be readable when I'm done so I
> > can't
> > just chop it into 80 char sections.
> > Is there a function that does this or at least one that makes it easy?
>
Quote:

> > Thanks
>
> How about this:http://www.microsoft.com/technet/scr...ames/solutions...
>
> Marco
>
> --
> Microsoft MVP - Windows PowerShellhttp://www.microsoft.com/mvp
>
> PowerGadgets MVPhttp://www.powergadgets.com/mvp
>
> Blog:http://marcoshaw.blogspot.com
I kind of thought that might be the way folks would suggest.
I'll probably tweak it Tuesday it to split text (like
qualified file or table names) that might otherwise overflow
my 80 column limit because they don't contain spaces.
The other stuff at that link will probably be interesting
too. Maybe I'll have time to browse.
Thanks.
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Wrap in Hotmail Marc Seidler Live Mail 2 04-10-2008 08:06 AM
Screen Wrap Fred Vista General 1 03-04-2008 02:38 PM
running large PS commands text wrap Mike Bonvie PowerShell 11 01-21-2008 11:00 PM
Word wrap John Barnes Vista General 7 10-08-2007 10:14 AM
word-wrap Thomas PowerShell 8 12-06-2006 07:03 PM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008