Question:
I’d like to take the first x amount of characters from $line and move them into a variable.
How do I do this?
Here is my existing code
1 2 3 4 5 6 |
$data = get-content "C:\TestFile.txt" foreach($line in $data) { if($line.length -gt 250){**get first x amount of characters into variable Y**} } |
Answer:
like this:
1 2 3 4 5 6 7 8 |
$data = get-content "TestFile.txt" $amount = 10; $y= @() foreach($line in $data) { if ( $line.length -gt 250){ $y += $line.substring(0,$amount) } } |