473,703 Members | 2,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.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(p arams char[])' has some invalid arguments

Source Error:

Line 234: string strFileNameOnSe rver = txtServername.V alue;
Line 235: string sep = @"\";
Line 236: Array a = strFileNameOnSe rver.Split(sep) ;

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

string strFileNameOnSe rver = txtServername.V alue;
char[] sep = {'\\'};
string[] a = strFileNameOnSe rver.Split(sep) ;

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

"merrittr" <me******@gmail .com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.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(p arams char[])' has some invalid arguments

Source Error:

Line 234: string strFileNameOnSe rver = txtServername.V alue;
Line 235: string sep = @"\";
Line 236: Array a = strFileNameOnSe rver.Split(sep) ;

Dec 28 '05 #2
Hello merrittr,

Why not to use
string fileName = @"C:\mydir\myfi le.ext";
string path = @"C:\mydir\" ;
string result;
result = Path.GetFileNam e(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

"Christophe r Reed" <ca****@nospam. nospam> wrote in message
news:O7******** ******@tk2msftn gp13.phx.gbl...
Try using this:

string strFileNameOnSe rver = txtServername.V alue;
char[] sep = {'\\'};
string[] a = strFileNameOnSe rver.Split(sep) ;

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

"merrittr" <me******@gmail .com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.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(p arams char[])' has some invalid arguments

Source Error:

Line 234: string strFileNameOnSe rver = txtServername.V alue;
Line 235: string sep = @"\";
Line 236: Array a = strFileNameOnSe rver.Split(sep) ;



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

using System;
using System.Diagnost ics;
using System.IO;

void SomeFunction()
{
string filePath = @"C:\SomeFolder \file.txt";
string fileName = Path.GetFileNam e(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
31177
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 will split myString up using the delimiter of 1 space so that
12
5680
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
2849
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
1678
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 (http://www.mvps.org/access/api/api0058.htm). I get "true" as the only return. Also, I am developing my first split database - BE to reside on a file server and the FE to be distributed (and updated with Tony Toews incredibly
4
5783
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
1732
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 for this so I used a Regex that splits the string at the first ³, ³ and again at the ³ (³. My problem is that I don¹t know how to extract the second member of the resulting array (FirstName) and assign it to another string. Using StringBuilder, as...
8
10212
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 from a string. I will explain why. I am creating a page that will add users to Active Directory. I collect the FirstName value (based on a pre-composed Excel spreadsheet) and want to strip just the first initial so I can create the sAMAccountName...
3
9667
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... field1...field2...field3...
5
5871
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() = Microsoft.VisualBasic.Strings.Split(aLine, vbNewLine, -1, CompareMethod.Binary)
0
8740
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8657
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9236
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8988
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8946
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7839
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5918
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3108
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.