> $a.substring(14) will get the remainder of the string. *That what you
> were looking for or am I off?
Close but no milkshake - basically I want a way to be able to get a
substring without necessarily knowing that the end of the string is
near - I'm dealing with variable length records, where I can be sure
of the maximum length, but not that the actual length is always the
maximum length, so I hit the end of the string unexpectedly.
I've written a very basic 'sane' get-substring function which does
what I wish -
## Return a substring (sanely)
function Get-SubString( [string] $value, [int] $startOfRange, [int]
## How long is the string
$strLength = $value.length
## Last index in string (index starts from 0, string length starts
$strLastIndex = ($strLength - 1)
## Get number of characters in range (add one to include current
$rangeLength = ($strLastIndex - $startOfRange) + 1
## Check to ensure number of characters required
## does not exceed characters available in string
if ( $numOfChars -gt $rangeLength )
## return what we can
$numOfChars = $rangeLength
## Check to see if the first index is within string
if ( $startOfRange -gt $strLastIndex )
throw "Start index exceeds end boundary"
if ( $startOfRange -lt 0 )
throw "Start index exceeds start boundary"
## Do the sub string!
Passing an index either greater than or less than the string length
(-1 or 25 in the original string) throws an exception that can be
handled, otherwise it returns either exactly the number of characters
asked for, or as many as left in the string.
Maybe that gives a better idea of what I was asking?