Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Split/Comparing not working

$
0
0

hello, i’m having the following code:

foreach ($line in [System.IO.File]::ReadLines('C:templist.txt')) { $current = $line -split ' - ' if($previous -ne $current[0]){ Write-Output $current[0] } $previous=$current[0] } 

“list.txt” looks like this:

Hello World – 1 2 3

Hello World – 3 4 1

Good Morning – 2 4 1

Good Evening – 2 1 1

Good Evening – 1 1 1

Good Evening – 5 5 1

Hello – 3 1 3

Hello – 1 1 1

Good Day – 4 3 1

Good-Day – yes

Good-Day – no

I wish my output to be only the first part of each line. so output should be:

Hello World

Good Morning

Good Evening

Hello

Good Day

Good-Day

I’ve tried splitting the string with:

$current = $line -split 's-s' 

as well, but it doesn’t work 🙁

any help apreciated.

submitted by /u/salatfinger
[link] [comments]

The post Split/Comparing not working appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images