asp.net foreach traversal array

Source: Internet
Author: User
Tags foreach

ASP tutorial. NET foreach Traversal array
This tutorial takes two examples to illustrate the use of foreach, where you get all the files from a specified directory and use a foreach traversal to show it. */

string pathstr = tbcontentaddress.text.tostring (). Trim ();
String path = Server.MapPath (PATHSTR);
int index = Path.lastindexof (');
string filepath = path.substring (0, index);
Response.Write (filepath);
string[] files = directory.getfiles (filepath, "*.*");
if (Files.length > 0)
{
String[] Filenamearr;
string filename1 = "";
string filename = "";
foreach (string filesname in Files)
{
filename = Filesname.replace (@ "d:www.111cn.net", "");
filename = Filename.replace (@ "", "/");
Filenamearr = Filename.split ('/');
filename1 = Filenamearr[filenamearr.length-1].tostring ();
}
}



Method Two


ArrayList list=new ArrayList ();
foreach (string filesname in Files)
{
StringBuilder str=new StringBuilder ()
Str.append (Filesname.replace (@ "d:www.111cn.net", ""));
Str.append ("|");
Str.append (Filename.replace (@ "", "/"));
Str.append ("|");
Str.append (Filenamearr = Filename.split ('/'));
Str.append ("|");
Str.append (Filenamearr[filenamearr.length-1].tostring ());

List.add (Str.tostring ());
}

/*
Realize the original is

string temp = Name.text; Reading data from a textbox
String Str= "";
foreach (Lcourse cou in Data.mycourse)//Traverse in list<lcourse>
{
if (condition)//judgment {
Str=cou.nage
Break Jump out of the loop
}

}
Str=

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.