I'm trying to remove the leading 0's in all values of an array within a two dimensional array.
Is there a library that can do this for me? I tried it with a foreach loop, but it only trims the current temp variable.
Here is the code:
[String[]]$arr1 = @('str1','str2','str3')
[String[]]$arr2 = @('str4','str5','str6')
[String[]]$arr3 = @('0str7')
[System.Object[]]$twoDimensionalArray = @()
[System.Object[]]$twoDimensionalArray += ,($arr1)
[System.Object[]]$twoDimensionalArray += ,($arr2)
[System.Object[]]$twoDimensionalArray += ,($arr3)
Write-Host "Removing leading zeros from array in twoDimentionalArray..."
ForEach ($strValue in $twoDimensionalArray[2])
{
$strValue = $strValue.TrimStart('0')
}
Write-Host "Leading zero's are removed."
Write-Host ""
Write-Host '$strValue =' $strValue
Write-Host '$twoDimensionalArray[2] =' $twoDimensionalArray[2]
Write-Host ""
Output (0str7)
Removing leading zeros from array in twoDimentionalArray...
Leading zero's are removed.
$strValue = str7
$twoDimensionalArray[2] = 0str7
Desired Output (str7)
Removing leading zeros from array in twoDimentionalArray...
Leading zero's are removed.
$strValue = str7
$twoDimensionalArray[2] = str7
Any ideas?