|
-
Aug 26th, 2005, 03:02 PM
#1
Thread Starter
Hyperactive Member
Split Function <RESOLVED>
Hi!
I am develeoping an application in asp.net with c# as the code behind.
I want to extract the file name form a string say, "C\documents\abc\abc.doc".
I have to get abc.doc in a variable.
I wanted to use the Split function and get the last item of the array, which would have given me the file name.
But, I am not been able to do so.
My code is
Code:
string strDocumentName = System.Web.HttpContext.Current.Request.Files[0].FileName.ToString();
string[]arrFile = strDocumentName.Split('\');
//Loop through the array arrFile
for(int i=0;i<=arrFile.GetUpperBound(0);i++)
{
strDocumentName = arrFile.GetValue(i).ToString();
}
Th problem is Split function gives an error with the delimeter (\). With every other delimiter it works fine.
Pls help.
Last edited by sinha; Aug 31st, 2005 at 03:46 PM.
Thanks.
-
Aug 26th, 2005, 04:18 PM
#2
Re: Split Function
Check out the IO.PATH name space. In VB.Net you would use:
VB Code:
dim sFilename as String = system.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.Files[0].FileName)
-
Aug 28th, 2005, 12:50 PM
#3
Re: Split Function
\ is an escape character - to fix your method, use Split('\\') instead.
wild_bill's option is somewhat cleaner though
-
Aug 31st, 2005, 03:46 PM
#4
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|