Need help creating old school file headers - plain text ASCII
i need figuring out how pass arguments function (yet written) place argument values @ specific locations in string. so, let's have line 5 pieces of information. #1 start @ column2 , ends @ column4. #2 starts @ column 6 , ends @ column 15. etc. first thought using -f format approach, but, need handle 2 things: 1) if string shorter "field" width, fills blanks, and, 2) if string longer "field" width, chops off irrelevant characters. being vague because have never approached problem , have ideas in head, but, not sure if apply.
something this?
$string1 = "teststring" $string2 = "newtest" $string3 = "alongstring" $string4 = "s" $string5 = "anotherlongstring" $pad = " " $newstring = $pad $newstring += $string1.substring(0,3) $newstring += $pad $newstring += $pad $newstring += $string2.substring(0,[system.math]::min(9, $string2.length)) $newstring += $pad $newstring += $string3.substring(0,[system.math]::min(3, $string3.length)) $newstring += $pad $newstring += $string4.substring(0,[system.math]::min(8, $string4.length)) $newstring += $pad $newstring += $string5.substring(0,[system.math]::min(8, $string5.length)) $newstringkarl
when see answers , helpful posts, please click vote helpful, propose answer, and/or mark answer
blog: http://unlockpowershell.wordpress.com
book: windows powershell 2.0 bible
e-mail: -join ("6b61726c6d69747363686b65406d742e6e6574"-split"(?<=\g.{2})",19|%{[char][int]"0x$_"})
Windows Server > Windows PowerShell
Comments
Post a Comment