0

Hi,

In an old thread, it was explained how to replace a value in an array element. However, it does not work for me. Running my VS 2008 debugger, I can see that all variables are set and accurate, but the Array.Replace does not work. Any ideas?

Here's my code:

if (values[i].ToString() == casprID && values[i + 1] == msNo)
{
   values[i] = values[i].Replace(values[i].ToString(), casprID.ToString());
}

Thank you,

jharter

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by alc6379
0

What type is your values array? What happens when you run the code? Does the code actually run the replace line? What data is there in the array and what do you expect the replace to do?

0

Are you sure you're using Array.Replace, there?

if (values[i].ToString() == casprID && values[i + 1] == msNo)
{
   values[i] = values[i].Replace(values[i].ToString(), casprID.ToString());
}

should be

if (values[i].ToString() == casprID && values[i + 1] == msNo)
{
   values[i] = values.Replace(values[i].ToString(), casprID.ToString());
}

it's a subtle bug-- you were doing String.Replace, it looked like, on an element of the array, rather than replacing the element itself.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.