Hi sirbounty ,
since the string size in my app is dynamic, if use string [], how can define size? Thanks.
Main Topics
Browse All TopicsHi experts,
I have string ="11/111/112/113/114/115/"
I need convert it into ArrayList() by using C#
ArrayList displayList = new ArrayList();
displayList[0] = 11;
displayList[1] = 111;
displayList[2] = 112;
displayList[3] = 113;
displayList[4] = 114;
displayList[5] = 115;
Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi dtwoway;
This should do what you want.
' Test Data
string input = "11/111/112/113/114/115/";
' This if statement is needed to remove the last / at the end of the string
' String.Split will give an empty element because of it.
if( input.Substring(input.Leng
input = input.Substring( 0, input.Length - 1);
}
ArrayList displayList = new ArrayList();
displayList.AddRange( input.Split('/') );
Fernando
Hi Fernando,
Thank you for comments. It works. But I still have some question to ask you. Below is my original code which didn't work:
string cType = group.CustomerTypeID; //test data '11/111/112/113/114/115/'
String cTypeList = new String();
cTypeList = cType.Split("/");
ArrayList displayDetail1 = new ArrayList();
for (int j = 0; j < cTypeList.Length; j++)
{ displayDetail.Add(cTypeLis
I don't know why I need to remove the last '/ ' at the end of the string, otherwise String.Split will give an empty element because of it.
Hi dtwoway;
I modified your code below so that it should work.
string cType = group.CustomerTypeID; //test data '11/111/112/113/114/115/'
string[] cTypeList;
cTypeList = cType.Split('/');
ArrayList displayDetail1 = new ArrayList();
for (int j = 0; j < cTypeList.Length; j++)
{ displayDetail1.Add(cTypeLi
In your original code you had this:
String cTypeList = new String();
The above statement is incomplete. This form requires at minimum 1 parameter to initialize the string and not a string array. For example the following line of code will initialize the variable cTypeList to a string of 10 A's.
string cTypeList = new string('A', 10); // = "AAAAAAAAAA"
To create an array of strings you can use the following statement.
string[] cTypeList;
The next thing that I found was this statement.
cTypeList = cType.Split("/");
The String.Split method take an array of Unicode characters and not a string of characters. So it should be like this.
cTypeList = cType.Split('/'); // meaning the Unicode char / and not string
The last thing I found was a type O, you declared the ArrayList as displayDetail1 but when you used it you called it displayDetail.
Just one more thing in this case it would be more efficient to create the ArrayList as follows:
displayDetail1.AddRange( cTypeList );
and not use the for loop.
Fernando
Hi dtwoway;
I forgot to answer this question you had. "I don't know why I need to remove the last '/ ' at the end of the string, otherwise String.Split will give an empty element because of it."
string cType = "11/111/112/113/114/115/";
The String.Split examines each character and assigns it to the current element in the array. When it gets to a character that it must do a split on it deletes the split character and adds another element to the array and then starts the process all over again. So when it gets to the last '/' character it deletes it and adds another element to the array and because there are no more characters that element of the array is empty. So the following statement:
cTypeList = cType.Split('/');
will assign to cTypeList the following stings:
cTypeList[0] = "11"
cTypeList[1] = "111"
cTypeList[2] = "112"
cTypeList[3] = "113"
cTypeList[4] = "114
cTypeList[5] = "115"
cTypeList[6] = ""
Removing the last '/' in the original string will give a array with elements 0 - 5 leaving out the empty element 6.
Fernando
string values = "11/111/112/113/114/115/";
string[] objchar = values.Split('/');
ArrayList objArrayList = new ArrayList();
for (int i = 0; i < objchar.Length; i++)
{
objArrayList.Add(objchar[i
}
for (int j = 0; j < objArrayList.Count-1; j++)
{
Response.Write("objArrayLi
}
Business Accounts
Answer for Membership
by: sirbountyPosted on 2006-12-26 at 12:49:43ID: 18199648
Perhaps this example would help you...
ds.com/Art icles/getA rticle.asp x? articleI D=28
{
// string seperated by colons ';'
string info = "mark;smith;123 csharp drive;toronto;canada";
string[] arInfo = new string[4];
// define which character is seperating fields
char[] splitter = {';'};
arInfo = info.Split(splitter);
for(int x = 0; x < arInfo.Length; x++)
{
Response.Write(arInfo[x] + "<br>");
}
}
ref:http://www.csharpfrien