String Manipulation

Hello,

I have an arraylist which contains strings like:
C:\Programs\Test\Value1.htm
C:\Programs\Test\Value2.htm
C:\Programs\Test\Value3.htm
C:\Programs\Test\Value14.htm

I want to create a new arraylist, using the above list, with the values: Value1, Value2, Value3, Value4..

How can I do this?
Thanks
Praveen

praveenuniAsked:
Who is Participating?
 
AaronReamsCommented:
Actually if you don't want the .htm on the end, you can strip it off by using this...

            for(int i=0; i<a1.Count; i++)
            {
                string[] strs = ((string)a1[i]).Split(new char[] {'\\'});
                a2.Add(strs[strs.Length-1].Substring(0,strs[strs.Length-1].IndexOf(".")));
            }
0
 
AaronReamsCommented:
           ArrayList a1 = new ArrayList();
            ArrayList a2 = new ArrayList();
            a1.Add(@"C:\Programs\Test\Value1.htm");
            a1.Add(@"C:\Programs\Test\Value2.htm");
            for(int i=0; i<a1.Count; i++)
            {
                string[] strs = ((string)a1[i]).Split(new char[] {'\\'});
                a2.Add(strs[strs.Length-1]);
            }

            for(int j=0; j<a2.Count; j++)
            {
                Debug.WriteLine((string)a2[j]);
            }
0
 
MudieCommented:
ArryList myArrayList = new ArrayList();

myArrayList.Add("Value1");
myArrayList.Add("Value2");
myArrayList.Add("Value3");

Hope that helps!
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
praveenuniAuthor Commented:
Thank You AaronReams. Wonderful Solution !

Thanks
Praveen
0
 
MudieCommented:
Sorry, ignore my first post.

This will do what you want:

private void button3_Click(object sender, System.EventArgs e)
            {
                  ArrayList myArrayList = new ArrayList();
                  myArrayList.Add("C:\\Programs\\Test\\Value1.htm");
                  myArrayList.Add("C:\\Programs\\Test\\Value2.htm");
                  myArrayList.Add("C:\\Programs\\Test\\Value3.htm");
                  myArrayList.Add("C:\\Programs\\Test\\Value14.htm");
                  
                  for (int i=0; i<myArrayList.Count; i++)
                  {
                  string strTemp = "";

                  strTemp = Convert.ToString(myArrayList[ i ]);
                  strTemp = strTemp.Replace("C:\\Programs\\Test\\", "");
                  myArrayList[ i ] = strTemp;
                  MessageBox.Show( Convert.ToString(myArrayList[ i ]) );
                  }
            }

That will work fine provided they are all in the same directory. Hope that helps.
0
 
AaronReamsCommented:
No problem.  Cheers -A.R.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.