Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
29
Task/Word-wrap/PowerShell/word-wrap.psh
Normal file
29
Task/Word-wrap/PowerShell/word-wrap.psh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
function wrap{
|
||||
$divide=$args[0] -split " "
|
||||
$width=$args[1]
|
||||
$spaceleft=$width
|
||||
|
||||
foreach($word in $divide){
|
||||
if($word.length+1 -gt $spaceleft){
|
||||
$output+="`n$word "
|
||||
$spaceleft=$width-($word.length+1)
|
||||
} else {
|
||||
$output+="$word "
|
||||
$spaceleft-=$word.length+1
|
||||
}
|
||||
}
|
||||
|
||||
return "$output`n"
|
||||
}
|
||||
|
||||
### The Main Thing...
|
||||
|
||||
$paragraph="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur."
|
||||
|
||||
"`nLine width:30`n"
|
||||
wrap $paragraph 30
|
||||
"========================================================="
|
||||
"Line width:100`n"
|
||||
wrap $paragraph 100
|
||||
|
||||
### End script
|
||||
Loading…
Add table
Add a link
Reference in a new issue