• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2820
  • Last Modified:

Replace value in Arraylist

I have an arraylist and I want to loop through the array and replace all the
""(or blank) values with string name "Pico". I'm doing this ..
foreach (String item in this.List1)
{
if (item == "")
{    item.Replace("","Pico"); // line 1  }
}

but when I'm trying to run the program -- its giving me compilation error " 
parameter old value cannot be of zero length in line 1". How can I achieve
this?
0
praveenuni
Asked:
praveenuni
  • 2
1 Solution
 
RealMrTeaCommented:
for(int i = 0; i < al.Count; i++)
{
  if((string)al[i] == string.Empty)
  {
    al[i] = "PICO";
  }
}

Something like the above is really more suited to what you are trying to do.
item.Replace("","Pico"); actually returns a value which would have to be assigned back to something but you can not assign it to item in this case because it is read only.

Hope that helps,
Eric
0
 
makerpCommented:
foreach (String item in this.List1)
{
  if (item == "" || item.Replace(" ","") == "")
  {    
    item = "Pico"; // line 1  
  }
}
0
 
RealMrTeaCommented:
Once again..."item" cannot be assigned to because it is read only.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now