473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

.Split a directory string

I have a string "c:\upload\file.txt"
what I want is the file name to do this I was trying split on \ but
I cant seem to get it to work?
Server Error in '/appform' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for
'string.Split(params char[])' has some invalid arguments

Source Error:

Line 234: string strFileNameOnServer = txtServername.Value;
Line 235: string sep = @"\";
Line 236: Array a = strFileNameOnServer.Split(sep);

Dec 28 '05 #1
4 7548
Try using this:

string strFileNameOnServer = txtServername.Value;
char[] sep = {'\\'};
string[] a = strFileNameOnServer.Split(sep);

--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"merrittr" <me******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I have a string "c:\upload\file.txt"
what I want is the file name to do this I was trying split on \ but
I cant seem to get it to work?
Server Error in '/appform' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for
'string.Split(params char[])' has some invalid arguments

Source Error:

Line 234: string strFileNameOnServer = txtServername.Value;
Line 235: string sep = @"\";
Line 236: Array a = strFileNameOnServer.Split(sep);

Dec 28 '05 #2
Hello merrittr,

Why not to use
string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string result;
result = Path.GetFileName(fileName);

instead of splitting ?

m> I have a string "c:\upload\file.txt"
m> what I want is the file name to do this I was trying split on \ but
m> I cant seem to get it to work?

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Dec 28 '05 #3

"Christopher Reed" <ca****@nospam.nospam> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
Try using this:

string strFileNameOnServer = txtServername.Value;
char[] sep = {'\\'};
string[] a = strFileNameOnServer.Split(sep);

--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"merrittr" <me******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I have a string "c:\upload\file.txt"
what I want is the file name to do this I was trying split on \ but
I cant seem to get it to work?
Server Error in '/appform' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for
'string.Split(params char[])' has some invalid arguments

Source Error:

Line 234: string strFileNameOnServer = txtServername.Value;
Line 235: string sep = @"\";
Line 236: Array a = strFileNameOnServer.Split(sep);



I prefer to let the framework do the "heavy lifting". Check out the
System.IO.Path class:

using System;
using System.Diagnostics;
using System.IO;

void SomeFunction()
{
string filePath = @"C:\SomeFolder\file.txt";
string fileName = Path.GetFileName(filePath);
Debug.WriteLine(fileName); // prints "file.txt"
}
Dec 28 '05 #4
whoaaa that was fast
this works perfectly thanks for the help guys

Dec 28 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
12
by: Martin Dieringer | last post by:
I am trying to split a file by a fixed string. The file is too large to just read it into a string and split this. I could probably use a lexer but there maybe anything more simple? thanks m.
1
by: porterboy76 | last post by:
QUESTION: How do I split a directory string into a list in Python, eg. '/foo/bar/beer/sex/cigarettes/drugs/alcohol/' becomes
6
by: Pat | last post by:
Hello, Two questions - hence the weird subject. First, anyone had luck with the Enumerating user accounts in a NT Domain module by Dev Ashish on Access Web...
4
by: Itzik | last post by:
can i split this string string str = "aa a - bb-b - ccc" with this delimiter string del = " - " i want recieve 3 items : "aa a" , "bb-b" , "ccc"
3
by: Stephan Bour | last post by:
I have a string ³Name² in the following format: ³LastName, FirstName (Department)² that comes from Active Directory. I need to extract the FirstName from the string. Substrings are not practical...
8
by: J Stoodley | last post by:
I am in a learning curve right now, and want to become well aquanted with VB.NET. So, I have two questions. 1 is technial the other is resource related. 1. I need to strip a single character...
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
5
by: kurt sune | last post by:
The code: Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" & vbNewLine Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf) Dim csvColumns2 As String() =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.