Here's my variables:
string FileName
string[] tmpSpl
string FilePath
Now, FileName has full path/filename, so, how do I Split FileName at the "\"
char into tmpSpl, then redim preserve tmpSpl by one less, the rejoin it all
into FilePath. I can do this very easily in VB.NET, but can't find anything
on how to do it in C#
Thanks,
JLW 6 3771
JLW wrote: Here's my variables: string FileName string[] tmpSpl string FilePath
Now, FileName has full path/filename, so, how do I Split FileName at the "\" char into tmpSpl, then redim preserve tmpSpl by one less, the rejoin it all into FilePath. I can do this very easily in VB.NET, but can't find anything on how to do it in C#
Thanks, JLW
Look in .NET docs for:
// join & split
String.Join(...)
string.Split(...)
// redim
Array.Copy(...)
// and ;)
Path.DirectorySeparatorChar
Cheers!
Marcin
I am not eactly sure what you are trying to do. but you should look in to
the System.IO.Path object.
using System.IO; // at the top
example 1:
string fliename = @"C:\test\mysong.mp3";
Path.GetPathRoot(filename); // c:\test
Path.GetFileName(filename); // song.mp3
Path.ChangeExtension(filename, ".wav"); // c:\test\song.wav
Path.GetDirectoryName(filename); // returns test
Path.GetFileNameWithoutExtention(filename); // returns song
exmple 2:
string path = "c:\test";
string path2 = "c:\test\";
string file = "song.mp3";
Path.Combine(path, file); // returns C:\test\mysong.mp3
Path.Combine(path2, file); // also returns C:\test\mysong.mp3
For you problem I would probably use
string[] rootPath = Path.GetDirectoryName(filename).Split('\\');
"JLW" <as***@someplace.com> wrote in message
news:Ow**************@TK2MSFTNGP12.phx.gbl... Here's my variables: string FileName string[] tmpSpl string FilePath
Now, FileName has full path/filename, so, how do I Split FileName at the
"\" char into tmpSpl, then redim preserve tmpSpl by one less, the rejoin it
all into FilePath. I can do this very easily in VB.NET, but can't find
anything on how to do it in C#
Thanks, JLW
The problem I'm having with split is "\" is a line terminantor char, and I'm
getting just that error. This is all in a function that is being passed the
full path/filename as an argument, and I put a break on the function, and it
doesn't come acrossed as "C:\\path\\file" but "C:\path\file", so that just
isn't working right.
Thanks again,
JLW
"Marcin Grzębski" <mg*******@taxussi.spam.com.stop.pl> wrote in message
news:c7***********@mamut.aster.pl... JLW wrote:
Here's my variables: string FileName string[] tmpSpl string FilePath
Now, FileName has full path/filename, so, how do I Split FileName at the
"\" char into tmpSpl, then redim preserve tmpSpl by one less, the rejoin it
all into FilePath. I can do this very easily in VB.NET, but can't find
anything on how to do it in C#
Thanks, JLW
Look in .NET docs for:
// join & split String.Join(...) string.Split(...)
// redim Array.Copy(...)
// and ;) Path.DirectorySeparatorChar
Cheers!
Marcin
Try Split("\\")
"JLW" <as***@someplace.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... The problem I'm having with split is "\" is a line terminantor char, and
I'm getting just that error. This is all in a function that is being passed
the full path/filename as an argument, and I put a break on the function, and
it doesn't come acrossed as "C:\\path\\file" but "C:\path\file", so that just isn't working right.
Thanks again, JLW "Marcin Grzębski" <mg*******@taxussi.spam.com.stop.pl> wrote in message news:c7***********@mamut.aster.pl... JLW wrote:
Here's my variables: string FileName string[] tmpSpl string FilePath
Now, FileName has full path/filename, so, how do I Split FileName at
the "\" char into tmpSpl, then redim preserve tmpSpl by one less, the rejoin
it all into FilePath. I can do this very easily in VB.NET, but can't find anything on how to do it in C#
Thanks, JLW
Look in .NET docs for:
// join & split String.Join(...) string.Split(...)
// redim Array.Copy(...)
// and ;) Path.DirectorySeparatorChar
Cheers!
Marcin
AFter playing around, this works:
Path.GetDirectoryName(FileName)
Thanks again guys, it was really starting to drive me nutz!
JLw
"Ben Dewey" <be*******@scientiae.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... I am not eactly sure what you are trying to do. but you should look in to the System.IO.Path object.
using System.IO; // at the top
example 1: string fliename = @"C:\test\mysong.mp3"; Path.GetPathRoot(filename); // c:\test Path.GetFileName(filename); // song.mp3 Path.ChangeExtension(filename, ".wav"); // c:\test\song.wav Path.GetDirectoryName(filename); // returns test Path.GetFileNameWithoutExtention(filename); // returns song
exmple 2: string path = "c:\test"; string path2 = "c:\test\"; string file = "song.mp3";
Path.Combine(path, file); // returns C:\test\mysong.mp3 Path.Combine(path2, file); // also returns C:\test\mysong.mp3
For you problem I would probably use string[] rootPath = Path.GetDirectoryName(filename).Split('\\');
"JLW" <as***@someplace.com> wrote in message news:Ow**************@TK2MSFTNGP12.phx.gbl... Here's my variables: string FileName string[] tmpSpl string FilePath
Now, FileName has full path/filename, so, how do I Split FileName at the "\" char into tmpSpl, then redim preserve tmpSpl by one less, the rejoin it all into FilePath. I can do this very easily in VB.NET, but can't find anything on how to do it in C#
Thanks, JLW
JLW,
Just to let you know when working with strings that have backslashes there
are two ways of doing it.
1. "C:\\test\\somefile.txt";
2. @"C:\test\somefile.txt";
This should help you with some of your escaping issues.
"JLW" <as***@someplace.com> wrote in message
news:Ot**************@TK2MSFTNGP11.phx.gbl... AFter playing around, this works: Path.GetDirectoryName(FileName) Thanks again guys, it was really starting to drive me nutz!
JLw
"Ben Dewey" <be*******@scientiae.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... I am not eactly sure what you are trying to do. but you should look in
to the System.IO.Path object.
using System.IO; // at the top
example 1: string fliename = @"C:\test\mysong.mp3"; Path.GetPathRoot(filename); // c:\test Path.GetFileName(filename); // song.mp3 Path.ChangeExtension(filename, ".wav"); // c:\test\song.wav Path.GetDirectoryName(filename); // returns test Path.GetFileNameWithoutExtention(filename); // returns song
exmple 2: string path = "c:\test"; string path2 = "c:\test\"; string file = "song.mp3";
Path.Combine(path, file); // returns C:\test\mysong.mp3 Path.Combine(path2, file); // also returns C:\test\mysong.mp3
For you problem I would probably use string[] rootPath = Path.GetDirectoryName(filename).Split('\\');
"JLW" <as***@someplace.com> wrote in message news:Ow**************@TK2MSFTNGP12.phx.gbl... Here's my variables: string FileName string[] tmpSpl string FilePath
Now, FileName has full path/filename, so, how do I Split FileName at
the "\" char into tmpSpl, then redim preserve tmpSpl by one less, the rejoin
it all into FilePath. I can do this very easily in VB.NET, but can't find anything on how to do it in C#
Thanks, JLW
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave Brueck |
last post by:
Below is some information I collected from a *small* project in which I wrote
a Python version of a Java application. I share this info only as a data
point (rather than trying to say this data...
|
by: Marek Malowidzki |
last post by:
Hi all,
I am writing a component that exposes a C++ library as a .NET
component. The approach is somewhat automatic: every library C++ class
has its managed C++ counterpart that keeps a pointer...
|
by: Bo Peng |
last post by:
Dear List,
It is not clear what the title means. :-) Here is the details:
I need to manage a big bunch of small objects, like
struct{
int a;
int b;
}obj;
|
by: Tony Lugg |
last post by:
I have an application with a document management form. When users add
documents to the form, I call the API function SHGetFileInfo to get
the associated large and small icons for the file. These...
|
by: Tony Lugg |
last post by:
I have an application with a document management form. When users add
documents to the form, I call the API function SHGetFileInfo to get
the associated large and small icons for the file. These...
|
by: Luc |
last post by:
I saw a few posts on this newsgroup about it but nothing to help me resolve
this problem:
We designed a window in .NET on a platform using small fonts (120 ppp). But
this window will run on...
|
by: =?Utf-8?B?VzFsZDBuZTc0?= |
last post by:
When one architects a new project one of the first steps in the decision is
to decide on the layers. (In my opinion anyway)
One architecture that I have used before is to go solid OO and create...
|
by: elty123 |
last post by:
I have a small C# program (about 400 lines of code) that is only 28kb
after compiled.
However when it runs (takes a whole 5 seconds) it takes up nearly 20MB
of memory and I don't see why.
...
|
by: JohnQ |
last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post).
It would be more than a little bit nice if C++ was much "cleaner" (less
complex) so that it wasn't a major world wide...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: Shćllîpôpď 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |