I’m trying to strip of a portion of a string into a new variable, and am having issues as to how to substring into the starting position I need.
The actual starting position isn’t consistent that I could use that value. The data I want to strip off isn’t consistent such that I could count from the end back to where I need to start.
The only thing I know for certain is there are 3 occurrences of a blank prior to the data I need. After I encounter the 3rd blank, then I want to strip off everything after that.
I’ve been playing with this code, but it only strips off the value prior to the first blank(Value1). It does continue to loop through the While statement, but doesn’t strip off Value2 or Value3 for me(I want everything following with Value4).
$data = ("Value1 Value2 Value3 Value4 Value5 Value6","Value1 Value2 Value3 Value4 Value5","Value1 Value2 Value3 Value4 Value5 Value6 Value7")
ForEach ($Row in $data)
{
$i=1
$FName = $null
While ($i -le "3")
{
$Row = $Row.Substring($Row.IndexOf(" "))
write-Host "Row: " $i $Row
$i++
}
$FName = $Row
write-Host "Full Name: "$FName
}
Thanks