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 3789
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.DirectoryS eparatorChar
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\myson g.mp3";
Path.GetPathRoo t(filename); // c:\test
Path.GetFileNam e(filename); // song.mp3
Path.ChangeExte nsion(filename, ".wav"); // c:\test\song.wa v
Path.GetDirecto ryName(filename ); // returns test
Path.GetFileNam eWithoutExtenti on(filename); // returns song
exmple 2:
string path = "c:\test";
string path2 = "c:\test\";
string file = "song.mp3";
Path.Combine(pa th, file); // returns C:\test\mysong. mp3
Path.Combine(pa th2, file); // also returns C:\test\mysong. mp3
For you problem I would probably use
string[] rootPath = Path.GetDirecto ryName(filename ).Split('\\');
"JLW" <as***@someplac e.com> wrote in message
news:Ow******** ******@TK2MSFTN GP12.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\fi le", so that just
isn't working right.
Thanks again,
JLW
"Marcin Grzębski" <mg*******@taxu ssi.spam.com.st op.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.DirectoryS eparatorChar
Cheers!
Marcin
Try Split("\\")
"JLW" <as***@someplac e.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.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\fi le", so that just isn't working right.
Thanks again, JLW "Marcin Grzębski" <mg*******@taxu ssi.spam.com.st op.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.DirectoryS eparatorChar
Cheers!
Marcin
AFter playing around, this works:
Path.GetDirecto ryName(FileName )
Thanks again guys, it was really starting to drive me nutz!
JLw
"Ben Dewey" <be*******@scie ntiae.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.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\myson g.mp3"; Path.GetPathRoo t(filename); // c:\test Path.GetFileNam e(filename); // song.mp3 Path.ChangeExte nsion(filename, ".wav"); // c:\test\song.wa v Path.GetDirecto ryName(filename ); // returns test Path.GetFileNam eWithoutExtenti on(filename); // returns song
exmple 2: string path = "c:\test"; string path2 = "c:\test\"; string file = "song.mp3";
Path.Combine(pa th, file); // returns C:\test\mysong. mp3 Path.Combine(pa th2, file); // also returns C:\test\mysong. mp3
For you problem I would probably use string[] rootPath = Path.GetDirecto ryName(filename ).Split('\\');
"JLW" <as***@someplac e.com> wrote in message news:Ow******** ******@TK2MSFTN GP12.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\\some file.txt";
2. @"C:\test\somef ile.txt";
This should help you with some of your escaping issues.
"JLW" <as***@someplac e.com> wrote in message
news:Ot******** ******@TK2MSFTN GP11.phx.gbl... AFter playing around, this works: Path.GetDirecto ryName(FileName ) Thanks again guys, it was really starting to drive me nutz!
JLw
"Ben Dewey" <be*******@scie ntiae.com> wrote in message news:%2******** ********@TK2MSF TNGP12.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\myson g.mp3"; Path.GetPathRoo t(filename); // c:\test Path.GetFileNam e(filename); // song.mp3 Path.ChangeExte nsion(filename, ".wav"); // c:\test\song.wa v Path.GetDirecto ryName(filename ); // returns test Path.GetFileNam eWithoutExtenti on(filename); // returns song
exmple 2: string path = "c:\test"; string path2 = "c:\test\"; string file = "song.mp3";
Path.Combine(pa th, file); // returns C:\test\mysong. mp3 Path.Combine(pa th2, file); // also returns C:\test\mysong. mp3
For you problem I would probably use string[] rootPath = Path.GetDirecto ryName(filename ).Split('\\');
"JLW" <as***@someplac e.com> wrote in message news:Ow******** ******@TK2MSFTN GP12.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 "proves" something) to consider
the next time the "Python makes developers more productive" thread starts up
again.
Background
==========
An employee who left our company had written a log processor we use to read
records from text files (1...
|
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 to the unmanaged
class instance.
As usually in such a scenario, the IDisposable/Dispose()/Dispose(bool)
pattern should be used. The problem is that in my approach it is often
impractical, as the library's unmanaged objects are quite small and
|
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 icons are
added to two ImageList objects which are bound to a ListView control,
and everything looks great. I am saving the icons to a SQL Server
table by using Icon.Save to a stream and assigning the byte array to
the field, then loading them...
|
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 icons are
added to two ImageList objects which are bound to a ListView control,
and everything looks great. I am saving the icons to a SQL Server
table by using Icon.Save to a stream and assigning the byte array to
the field, then loading them...
| |
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 servers configured with large fonts. For a reason I
cant explain, not only the font changes when settings the window on large
font but all the widgets seem to be resized. This is kind of problematic
because I have to redraw (resize) all the widgets...
|
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
objects, which normally are very small and only deals with the stuff
pertaining to that object, then break it down into Business Process, Process
Controllers and Data Access Objects for each "Object", each of which is
created in it's very own .Net...
|
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.
Some of the assembly I used:
using System;
using System.Collections.Generic;
|
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 untaking to create a toolchain
for it. Way back when, there used to be something called "Small C". I wonder
if the creator(s) of that would want to embark on creating a nice little
Small C++ compiler devoid of C++ language features that make...
|
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...
|
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,...
| |
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |