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

remove spaces from end of string

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 06-13-2007   #1 (permalink)
Frank
Guest


 

remove spaces from end of string

Hi,

What is the best way to remove spaces from the end of a string, ie.

$string = "abcdef 123 "

I want to trim the string to be "abcdef 123"

thanks,



My System SpecsSystem Spec
Old 06-13-2007   #2 (permalink)
Keith Hill [MVP]
Guest


 

Re: remove spaces from end of string

"Frank" <Frank@discussions.microsoft.com> wrote in message
news:1E13887D-C790-4746-9810-642F97F01F88@microsoft.com...
> Hi,
>
> What is the best way to remove spaces from the end of a string, ie.
>
> $string = "abcdef 123 "
>
> I want to trim the string to be "abcdef 123"


$string = "abcdef 123 ".TrimEnd()

--
Keith

My System SpecsSystem Spec
Old 06-13-2007   #3 (permalink)
Hal Rottenberg
Guest


 

Re: remove spaces from end of string

On Jun 13, 1:17 am, "Keith Hill [MVP]"
<r_keith_h...@mailhot.nospamIdotcom> wrote:
> > I want to trim the string to be "abcdef 123"

>
> $string = "abcdef 123 ".TrimEnd()


Another related technique which I found useful:

# "abcdef 123 ".Split(" ",
[StringSplitOptions]::RemoveEmptyEntries)
abcdef
123

This tip came via Bruce Payette's "Powershell in Action" book.
Portion available online: http://www.microsoft.com/technet/scr...ette1.mspx#EKC

My System SpecsSystem Spec
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove Newline from String Kurt PowerShell 1 07-08-2008 12:07 PM
VBScript run generates errors with blank spaces in the string to beexecuted newbie123 VB Script 2 05-22-2008 08:35 AM
problems with $var | select-string -pattern $string -q Ben Christian PowerShell 3 02-08-2008 12:41 PM
String PRODUCT_NAME was not found in string table Extracampine Vista General 3 02-12-2007 06:15 AM
Why does get-content on a text file remove crlf when cast to a string? Mark PowerShell 7 09-22-2006 11:50 AM


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

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 47 48 49 50 51