I was looking at some code from a co-worker and it looks as though they're using a Char Array in their String.Replace:
txtPAPTransit.Text = g_aAllBranches(instApplication.branchForCumisReporting.ToLower).transit.ToString.Replace({" "c, "-"c}, "").Substring(3)
Which doesn't remove the "-" from the string in the textbox (the string being 123-45678). When I try it making the Substring as 4 instead of 3, it works. Which strikes me as very odd, why would it behave like this in this case when the index is 0 based?
When I write the replace like this it works fine:
txtPAPTransit.Text = g_aAllBranches(instApplication.branchForCumisReporting.ToLower).transit.ToString.Replace("-"c, "").Substring(3)
Afterwards the string appears as 45678, which is the correct result.
Why would it work in the case of replacing the substring with 4 as I mention above? And why does it have a problem with the char array?
{" "c, "-"c}will equate to " " + " -" not act as a multiple replace for any space and any "-". Thus nothing is removed. Replace takes a single char or a string: an array of char is a string so nothing happens unless it is "123 -45678"..Replace(" "c, "").Replace("-"c, "")would be the way to do both/either