Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

can powershell detect "invisible characters" ?

29 views
Skip to first unread message

IT Staff

unread,
Jan 3, 2010, 9:32:39 PM1/3/10
to
Say i have a text file that contains some computer names eg

pclist.txt
pc001
pc002
etc

I want to make sure that each pc has NO trailing invisible characters. Eg
pc001 must not have pc001<blank space><blank space>

What is the .net class to use ?


PaulChavez

unread,
Jan 3, 2010, 11:31:01 PM1/3/10
to
Trim() method on String class will do this.

PS C:\> " aaa","aaa " | %{ "[$_]" }
[ aaa]
[aaa ]

PS C:\> " aaa","aaa " | %{ "[$($_.trim())]" }
[aaa]
[aaa]

-Paul

"IT Staff" wrote:

> .
>

IT Staff

unread,
Jan 4, 2010, 4:27:12 AM1/4/10
to
sorry i m not looking for a way to trim trailing characters.

Are there any functions to *determine* that a string contains trailing
characters ?

"PaulChavez" <PaulC...@discussions.microsoft.com> wrote in message
news:16C615C9-98F4-4D5C...@microsoft.com...

Rob Campbell

unread,
Jan 4, 2010, 8:07:01 AM1/4/10
to
You can use -match to check for trailing whitespace:

get-content list.txt |% {if ($_ -match "\s$"){write-host "Entry $($_)
contains trailing whitespace."}}

"IT Staff" wrote:

> .
>

Martin Zugec

unread,
Jan 4, 2010, 4:14:14 PM1/4/10
to
"aaa ".TrimEnd()

Martin

"IT Staff" <jkk...@hotmail.com> wrote in message
news:uSD2aASj...@TK2MSFTNGP06.phx.gbl...

0 new messages