I have an array element that I am trying to replace all the numbers with letters. This is the array element before manipulation:
$a[0].object
--- OUTPUT ---
518773112
I convert the number to a string and store it in $e. Then I find the length of that string and store that in $d
$e = $a[0].object.ToString()
$d = $a[0].object.ToString().length
$e
$d
---OUTPUT---
518773112
9
Then I try to looping through the string to replace the numbers with letters. I place $i in the Substring to get the number that I'm trying to replace. Then I use an if-statement to see if that substring is equal to a number, and if so, then I use the replace method to try and replace the number with a letter.
for($i=0; $i -lt $d; $i++){
$pos = $e.Substring($i,1)
if($pos -eq '0'){$e += $pos.replace('0', 'A')}
if($pos -eq '1'){$e += $pos.replace('1', 'B')}
if($pos -eq '2'){$e += $pos.replace('2', 'C')}
if($pos -eq '3'){$e += $pos.replace('3', 'D')}
if($pos -eq '4'){$e += $pos.replace('4', 'E')}
if($pos -eq '5'){$e += $pos.replace('5', 'F')}
if($pos -eq '6'){$e += $pos.replace('6', 'G')}
if($pos -eq '7'){$e += $pos.replace('7', 'H')}
if($pos -eq '8'){$e += $pos.replace('8', 'I')}
if($pos -eq '9'){$e += $pos.replace('9', 'J')}
}
My issue though, is it will concatenate the letters to the end of the number string:
518773112FBIHHDBBC
Likely, because I have += in my then portion of my if-statement. However, when I replace += with = I get an error with my Substring method saying:
Exception calling "Substring" with "2" argument(s): "startIndex cannot be larger than length of string.
I've checked $i and $d and they are set correctly before I run the loop. So, I'm a little confused. What am I missing?