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

Recommended Answers

All 2 Replies

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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.