![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||