Connecting Tech Pros Worldwide Help | Site Map

Help!! How do I delete part of an array?

JLC JLC is offline
Member
 
Join Date: Sep 2006
Posts: 34
#1: Apr 10 '07
Hi,
I am very much a beginner and would love some help here.
I seem to get a blank line in the text box I am getting these entries from and I wanted to check for that in my array and then delete that part of the array (which would be the last entry).
But I am not sure what to put for the start index for the Remove method.

//if there are blank lines in the array, remove them
for (int i = 0; i < EntriesArray.Length; i++)
{
if (EntriesArray[i] == "")
{
EntriesArray[i].Remove( --what goes here?-- );
}
}

I see from the intellisense it is the start index...but when I put in 0 for starting at the beginning it doesn't work.

Thanks so much!
JL
SammyB's Avatar
Moderator
 
Join Date: Mar 2007
Location: Springfield, Ohio
Posts: 729
#2: Apr 10 '07

re: Help!! How do I delete part of an array?


Quote:

Originally Posted by JLC

Hi,
I am very much a beginner and would love some help here.
I seem to get a blank line in the text box I am getting these entries from and I wanted to check for that in my array and then delete that part of the array (which would be the last entry).
But I am not sure what to put for the start index for the Remove method.

//if there are blank lines in the array, remove them
for (int i = 0; i < EntriesArray.Length; i++)
{
if (EntriesArray[i] == "")
{
EntriesArray[i].Remove( --what goes here?-- );
}
}

I see from the intellisense it is the start index...but when I put in 0 for starting at the beginning it doesn't work.

Thanks so much!
JL

How have you defined EntriesArray?
Needs Regular Fix
 
Join Date: Jul 2006
Location: India,Hyderabad
Posts: 367
#3: Apr 11 '07

re: Help!! How do I delete part of an array?


Hello

Why you want to delete part of an array that too from your code you are trying to delete empty entries,which part of an array you want to delete,that starting in the middle to end or some entries in the middle only ,are you able to get the length of your array will it be constant or variable.

can you give some details so that i can reply
JLC JLC is offline
Member
 
Join Date: Sep 2006
Posts: 34
#4: Apr 11 '07

re: Help!! How do I delete part of an array?


Well I ended up using a list instead of an array. It made it easier to remove entries should they be blank.

SO I ended up with something like this.

//Check if the Old Public Key entered and the Domain are
//in the registry..if not return error
List<string> domainEntriesArray = new List<string>();
foreach(string entry in richTextBoxDomainPK.Lines)
{
domainEntriesArray.Add(entry);
}
//domainEntriesArray = richTextBoxDomainPK.Lines;
// string[] domainEntriesArray = richTextBoxDomainPK.Lines;
StringBuilder rejectedEntries = new StringBuilder();

//if there are blank lines in the array, remove them
for (int i = 0; i < domainEntriesArray.Count; i++)
{
if (String.IsNullOrEmpty(domainEntriesArray[i]))
{
domainEntriesArray.Remove(domainEntriesArray[i]);
}
}

Thanks everyone for the responses!

JLC
Reply