[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

String Manipulation

Posted on 2005-05-02
6
Medium Priority
?
296 Views
Last Modified: 2010-04-16
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

0
Comment
Question by:praveenuni
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:AaronReams
ID: 13911393
           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
 
LVL 2

Expert Comment

by:Mudie
ID: 13911396
ArryList myArrayList = new ArrayList();

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

Hope that helps!
0
 
LVL 8

Accepted Solution

by:
AaronReams earned 2000 total points
ID: 13911418
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:praveenuni
ID: 13911541
Thank You AaronReams. Wonderful Solution !

Thanks
Praveen
0
 
LVL 2

Expert Comment

by:Mudie
ID: 13911578
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
 
LVL 8

Expert Comment

by:AaronReams
ID: 13911610
No problem.  Cheers -A.R.
0

Featured Post

Industry Leaders: 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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

872 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