Replace value in Arraylist

Posted on 2005-03-21
Medium Priority
Last Modified: 2010-05-18
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
Question by:praveenuni
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

RealMrTea earned 500 total points
ID: 13595467
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,
LVL 10

Expert Comment

ID: 13595527
foreach (String item in this.List1)
  if (item == "" || item.Replace(" ","") == "")
    item = "Pico"; // line 1  

Expert Comment

ID: 13595549
Once again..."item" cannot be assigned to because it is read only.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question