473,387 Members | 1,465 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,387 software developers and data experts.

Finding Character in String

I want to return the name of the drawing file (DWG) from the end of a string.
The string will be of varying lengths... as well as the drawing file name
itself.

I could do it the long way by getting the length of the string, and
subtracting one character at a time until I hit the '\' character... then
I'll know how much to subtract to get my file name.

An example of the string is:
"P:\Projects\2004\10-02-230 (ProjectName\600 Drawings\E101.dwg"

But is there an easier (and faster) way to search for the last '\' character
in my string? (keep in mind that the number of '\' in each string will also
vary).

Thanks in advance!

Regards,

Bruce
Nov 22 '05 #1
9 1612
Hi Mr B,

Take a look at the instrrev function.

HTH,

Bernie Yaeger

"Mr. B" <Us**@NoWhere.com> wrote in message
news:7o********************************@4ax.com...
I want to return the name of the drawing file (DWG) from the end of a string. The string will be of varying lengths... as well as the drawing file name
itself.

I could do it the long way by getting the length of the string, and
subtracting one character at a time until I hit the '\' character... then
I'll know how much to subtract to get my file name.

An example of the string is:
"P:\Projects\2004\10-02-230 (ProjectName\600 Drawings\E101.dwg"

But is there an easier (and faster) way to search for the last '\' character in my string? (keep in mind that the number of '\' in each string will also vary).

Thanks in advance!

Regards,

Bruce

Nov 22 '05 #2
The System.IO.Path class is filled with static methods to deal with file and path names

string fileName = Path.GetFileName(yourPathString);
Nov 22 '05 #3
try this if you are doing directory enumeration
http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfsystemiofilesysteminfoclassextensiontop
ic.asp
-----Original Message-----
Hi Mr B,

Take a look at the instrrev function.

HTH,

Bernie Yaeger

"Mr. B" <Us**@NoWhere.com> wrote in message
news:7o********************************@4ax.com.. .
I want to return the name of the drawing file (DWG) from the end of a
string.
The string will be of varying lengths... as well as
the drawing file name itself.

I could do it the long way by getting the length of the string, and subtracting one character at a time until I hit the '\' character... then I'll know how much to subtract to get my file name.

An example of the string is:
"P:\Projects\2004\10-02-230 (ProjectName\600 Drawings\E101.dwg"
But is there an easier (and faster) way to search for

the last '\'character
in my string? (keep in mind that the number of '\' in
each string willalso
vary).

Thanks in advance!

Regards,

Bruce

.

Nov 22 '05 #4
With Deft Fingers, Mr. B <Us**@NoWhere.com> wrote:
I want to return the name of the drawing file (DWG) from the end of a string.
The string will be of varying lengths... as well as the drawing file name
itself.


Yeow! Thanks ALL... so many options to choose from... I'll try them all and
see where I get.

Thanks muchly!

bruce
Nov 22 '05 #5
Mr. B <Us**@NoWhere.com> wrote:
With Deft Fingers, Mr. B <Us**@NoWhere.com> wrote:
I want to return the name of the drawing file (DWG) from the end of a string.
The string will be of varying lengths... as well as the drawing file name
itself.


Yeow! Thanks ALL... so many options to choose from... I'll try them all and
see where I get.


While there are indeed lots of ways of approaching this, I'd be
surprised if Path.GetFileName or Path.GetFileNameWithoutExtension
didn't turn out to be the best one here, as they do *exactly* what it
sounds like you need.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #6
Hi Jon,

That was what Herfried had answered already in the VB.language group,
however you can not see that because Herfried is using a newsreader which
cannot crosspost when it is not in his range of standard newsgroups.

Therefore you was probably suprissed by the answer of mr. B.

Just to make it more clear for you.

Cor
While there are indeed lots of ways of approaching this, I'd be
surprised if Path.GetFileName or Path.GetFileNameWithoutExtension
didn't turn out to be the best one here, as they do *exactly* what it
sounds like you need.

Nov 22 '05 #7
I agree that these are the best :Path.GetFileName or
Path.GetFileNameWithoutExtension .

One alternative for finding the position of the last character in a string
which is not a file name is:
strFoo.LastIndexOf("\")

Dim somestring As String = "this is a long string"
Dim i As Integer = somestring.LastIndexOf("s")

i =15

--
Joe Fallon


"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mr. B <Us**@NoWhere.com> wrote:
With Deft Fingers, Mr. B <Us**@NoWhere.com> wrote:
I want to return the name of the drawing file (DWG) from the end of a string.The string will be of varying lengths... as well as the drawing file nameitself.


Yeow! Thanks ALL... so many options to choose from... I'll try them all and see where I get.


While there are indeed lots of ways of approaching this, I'd be
surprised if Path.GetFileName or Path.GetFileNameWithoutExtension
didn't turn out to be the best one here, as they do *exactly* what it
sounds like you need.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 22 '05 #8
Hi Joe,

That is what Bernie posted (although with the VB function equivalent from
it) and Herfried and Jon did give both independent from each other the
better alternative GetFilePath.

In this thread even a C# diehard as Jon did not come with the LastIndexOf. I
can assure you that all other posters active in this thread do know that
method very well. It was (by me, however I think also by the others)
express not given, so the OP would not become confused.

Do you think you help the OP with telling this worse method for this
problem.

Cor
Nov 22 '05 #9
I forgot to mention John. Q. sorry John,

Cor
Nov 22 '05 #10

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

Similar topics

5
by: lawrence | last post by:
"Garp" <garp7@no7.blueyonder.co.uk> wrote in message news:<_vpuc.1424$j_3.13346038@news-text.cableinet.net>... > "lawrence" <lkrubner@geocities.com> wrote in message >...
10
by: M Bourgon | last post by:
I'm trying to figure out how to find the last whitespace character in a varchar string. To complicate things, it's not just spaces that I'm looking for, but certain ascii characters (otherwise,...
2
by: B Moor | last post by:
I have a database with 100,000's records, each with a unique reference, eg A123BNK456 I would like to generate a search facility whereby we can choose an exact match or partial match, where the...
2
by: Mike P | last post by:
I want to find a particular character in a string, and then find the length of the string after this point in the string, so that I can do a rightpad on it if it is of a certain length (basically I...
4
by: David Warner | last post by:
Greetings! In looking into some C coding, I am looking for the C function that will search for multiple occurances of a same character in a string. For Instance: char str = "We the people...
14
by: Mr. B | last post by:
I want to return the name of the drawing file (DWG) from the end of a string. The string will be of varying lengths... as well as the drawing file name itself. I could do it the long way by...
2
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. ...
14
by: prasadjoshi124 | last post by:
Hi All, I am writing a small tool which is supposed to fill the filesystem to a specified percent. For, that I need to read how much the file system is full in percent, like the output given...
2
by: Lucas Kruijswijk | last post by:
Hello, I am making some site, where I use UTF-8 encoding. From PHP I send mail. But, if possible I want to send the mail in ISO-8859-1 or KOI8-R (because still some mailers have problem with...
2
by: Maxington | last post by:
The problem I am left with is that I need to split a string into substrings and determine the character location of the 30th occurance of "\n" string. I have a string that has "\n" within it and I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...

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.