Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - HowTo: Get Text from a file and put in a string.

Reply
 
Old 12-22-2006   #1 (permalink)
Brandon Shell


 
 

HowTo: Get Text from a file and put in a string.

I know I can use gc File.path, but that puts it in an object array... I want
it in a string. Maybe Im missing something simple here.


My System SpecsSystem Spec
Old 12-22-2006   #2 (permalink)
Rob Campbell


 
 

RE: HowTo: Get Text from a file and put in a string.

I don't know if there's an easier way or not, but

$a = gc File.path
$a = [string]::join(" ", $a)

should work.


"Brandon Shell" wrote:

> I know I can use gc File.path, but that puts it in an object array... I want
> it in a string. Maybe Im missing something simple here.
>
>

My System SpecsSystem Spec
Old 12-22-2006   #3 (permalink)
RichS


 
 

RE: HowTo: Get Text from a file and put in a string.

wouldn't

gc test.txt | out-string

do what you want
--
Richard Siddaway

Please note that all scripts are supplied "as is" and with no warranty


"Rob Campbell" wrote:

> I don't know if there's an easier way or not, but
>
> $a = gc File.path
> $a = [string]::join(" ", $a)
>
> should work.
>
>
> "Brandon Shell" wrote:
>
> > I know I can use gc File.path, but that puts it in an object array... I want
> > it in a string. Maybe Im missing something simple here.
> >
> >

My System SpecsSystem Spec
Old 12-22-2006   #4 (permalink)
Brandon Shell


 
 

Re: HowTo: Get Text from a file and put in a string.

Looks like it does. Thanks
"RichS" <RichS@discussions.microsoft.com> wrote in message
news:B1C1A757-8169-46C9-8AFE-4A4FA76F9343@microsoft.com...
> wouldn't
>
> gc test.txt | out-string
>
> do what you want
> --
> Richard Siddaway
>
> Please note that all scripts are supplied "as is" and with no warranty
>
>
> "Rob Campbell" wrote:
>
>> I don't know if there's an easier way or not, but
>>
>> $a = gc File.path
>> $a = [string]::join(" ", $a)
>>
>> should work.
>>
>>
>> "Brandon Shell" wrote:
>>
>> > I know I can use gc File.path, but that puts it in an object array... I
>> > want
>> > it in a string. Maybe Im missing something simple here.
>> >
>> >


My System SpecsSystem Spec
Old 12-22-2006   #5 (permalink)
Keith Hill [MVP]


 
 

Re: HowTo: Get Text from a file and put in a string.

"RichS" <RichS@discussions.microsoft.com> wrote in message
news:B1C1A757-8169-46C9-8AFE-4A4FA76F9343@microsoft.com...
> wouldn't
>
> gc test.txt | out-string
>


Or with the PowerShell Community Extensions installed you can do this:

> gc text.txt | join-string # no separator between strings
> gc text.txt | join-string -sep " "
> gc text.txt | join-string -NewLine # newline separator


There's also a corresponding Split-String. These are both thin wrappers
around String.Join/Concat/Split and Regex.Split. The cmdlets are a bit
nicer to deal with than the raw .NET methods.

--
Keith


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Concatenate text string and text in variable with no space between PowerShell
Concatenate text string and text in variable with no space between VB Script
Creating a Text string PowerShell
Howto: Add lines of text from a specific point in a text file.. VB Script
Why does get-content on a text file remove crlf when cast to a string? PowerShell


Vista Forums 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 Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46