473,387 Members | 1,520 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.

{simple} Extracting Substrings from textbox

I've been looking at .substring and .trim methods and I still have a question about extracting substrings from a textbox. Basically the textbox contains the full path to a file ... for example C:\testfile.txt or ... C:\download\temp\dlls\testfile.dll
I want to be able to extract the file name from this textbox (and put it in a string) when I click a button. Can someone illustrate how to write this line of code?
Nov 16 '05 #1
3 2635
War Eagle,

It's simple. Use the static GetFileName method on the Path class in the
System.IO namespace, like this:

// Get the filename.
string pstrFileName = System.IO.Path.GetFileName(textbox.Text);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"War Eagle" <Wa******@discussions.microsoft.com> wrote in message
news:DA**********************************@microsof t.com...
I've been looking at .substring and .trim methods and I still have a question about extracting substrings from a textbox. Basically the textbox
contains the full path to a file ... for example C:\testfile.txt or ...
C:\download\temp\dlls\testfile.dll I want to be able to extract the file name from this textbox (and put it

in a string) when I click a button. Can someone illustrate how to write
this line of code?
Nov 16 '05 #2


Exactly what I needed. Thank you!

"Nicholas Paldino [.NET/C# MVP]" wrote:
War Eagle,

It's simple. Use the static GetFileName method on the Path class in the
System.IO namespace, like this:

// Get the filename.
string pstrFileName = System.IO.Path.GetFileName(textbox.Text);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"War Eagle" <Wa******@discussions.microsoft.com> wrote in message
news:DA**********************************@microsof t.com...
I've been looking at .substring and .trim methods and I still have a

question about extracting substrings from a textbox. Basically the textbox
contains the full path to a file ... for example C:\testfile.txt or ...
C:\download\temp\dlls\testfile.dll
I want to be able to extract the file name from this textbox (and put it

in a string) when I click a button. Can someone illustrate how to write
this line of code?

Nov 16 '05 #3
This will work too.

FileInfo fInfo = new FileInfo(txtBox.text);
string fileName = fInfo.Name;

Shak.
"War Eagle" <Wa******@discussions.microsoft.com> wrote in message
news:DA**********************************@microsof t.com...
I've been looking at .substring and .trim methods and I still have a question about extracting substrings from a textbox. Basically the textbox
contains the full path to a file ... for example C:\testfile.txt or ...
C:\download\temp\dlls\testfile.dll I want to be able to extract the file name from this textbox (and put it

in a string) when I click a button. Can someone illustrate how to write
this line of code?
Nov 16 '05 #4

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

Similar topics

5
by: Chamomile | last post by:
I have to split strings of the type: $str1 =' Large ladies hats 1.365 0.334'; $str2 = 'Pins 0.335 0.22'; into separate variables (or array members) : say,...
7
by: cpp_weenie | last post by:
Given a std::string of the form "default(N)" where N is an integer number of any length (e.g. the literal string might be "default(243)"), what is the quickest way to extract the characters...
9
by: C3 | last post by:
I have to process some data in C that is given to me as a char * array. I have a fairly large number of substrings (well, they're not actually printable, but let's treat them as strings) that I...
5
by: ORC | last post by:
Is there an easy way to extract a number from a string like: result = ExtractNumber("this is a 4 string"); which should give the result = 4; Thanks Ole
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...
3
by: Alan LeHun | last post by:
I want to attach a context menu to multiple textboxes but I don't know how the extract the name of the textbox that is the subject of the event. I can't seem to do anything with "sender as...
8
by: girish | last post by:
Hi, I want to generate all non-empty substrings of a string of length >=2. Also, each substring is to be paired with 'string - substring' part and vice versa. Thus, gives me , , , , , ] etc....
4
by: ashilyas | last post by:
Hi all, I am new to this forum as well as Visual Basic. I haven't been able to find a resource that tells me what functions are available in Visual Basic like you can find the listing in C++...
2
by: Pilcrow | last post by:
This problem was raised in comp.lang.perl.misc, and the poster was concerned, among other things, by the speed of execution. Since C is faster than perl, I wonder how a C coder would solve it? ...
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: 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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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.