473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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?

Steven
Nov 16 '05 #1
3 14557
If you aren't completely intent on using a foreach, you
could simply switch to:

for(int x = 0; x < this.List1.Count; x++)
{
if((string)this.List1[x] == "")
{
this.List1[x] = "Pico";
}
}
-----Original Message-----
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 achievethis?

Steven
.

Nov 16 '05 #2
Thanks Brendan! That works

-- Steven

"Brendan Grant" <gr****@dahat.com> wrote in message
news:00****************************@phx.gbl...
If you aren't completely intent on using a foreach, you
could simply switch to:

for(int x = 0; x < this.List1.Count; x++)
{
if((string)this.List1[x] == "")
{
this.List1[x] = "Pico";
}
}
-----Original Message-----
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?

Steven
.

Nov 16 '05 #3
Steven wrote:
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?

Steven

Just an FYI, your code compiled for me with no errors. I cut and pasted
your code and used

ArrayList List1 = new ArrayList();

Thats all.

Paul
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: ALI-R | last post by:
Hi All, First of all I think this is gonna be one of those threads :-) since I have bunch of questions which make this very controversial:-0) Ok,Let's see: I was reading an article that When...
13
by: Dan Bass | last post by:
Say I've got an ArrayList, which contains a list of integers. Is it possible to get a reference to one of the integers contained within the collection so that changes to it are reflected in the...
12
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
26
by: Brett | last post by:
I have created a structure with five fields. I then create an array of this type of structure and place the structure into an array element. Say index one. I want to assign a value to field3 of...
4
by: serge | last post by:
I managed to put together C# code and have it do the following: 1- Get all the table names that start with the letter "Z" from sysobjects of my SQL 2000 database and put these table names...
4
by: Jon | last post by:
Hi, I have an arrayList that holds an ArrayObject with (Qty & ItemCode). e.g. arrayList.Add(New ArrayObject(Qty, ItemCode) However, I want to search the arrayList and check if the ItemCode...
3
by: mouac01 | last post by:
Newbie here. How do I do a find and replace in a binary file? I need to read in a binary file then replace a string "ABC" with another string "XYZ" then write to a new file. Find string is the...
3
by: sony.m.2007 | last post by:
Hi, I’m new to ASP.NET I have written a function with a return value. If the arguments to the functions are invalid means I’m giving exit(0) Else means do some process and return a value. When...
6
by: Slickuser | last post by:
Hi, I am picking up C#.net and I'm trying to add many values to one single key at different time in a loop. If the key already exist, append new value to previous? I'm not sure how to do that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.