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

end of string found

IndexOf gives you the start of the string found in another string. How do
you get the end of the string found?

I am trying to get the path of the startup:

string stemp = Application.StartupPath;

I then want to do something like:

stemp =
stemp.Substring(0,stemp.IndexOf(@"theFolder\")+Str ing.length((@"theFolder\"))
+ "afile.txt";

So that I would end up with something like:

c:\folder1\theFolder\afile.txt

I could do this by putting "theFolder" in a string and then taking the lengh
of the string in my Substring call,

var s = @"theFolder\";
stemp = stemp.Substring(0,stemp.IndexOf(s)+s.Length)) + "afile.txt";

but wanted to see if there was an easier way?

Thanks,

Tom


Jun 27 '08 #1
2 1087
On Fri, 23 May 2008 09:12:39 -0700, "tshad" <ts***@dslextreme.com>
wrote:
>IndexOf gives you the start of the string found in another string. How do
you get the end of the string found?
By adding the length of the search string, which is known.
>I am trying to get the path of the startup:

string stemp = Application.StartupPath;

I then want to do something like:

stemp =
stemp.Substring(0,stemp.IndexOf(@"theFolder\")+St ring.length((@"theFolder\"))
+ "afile.txt";

So that I would end up with something like:

c:\folder1\theFolder\afile.txt

I could do this by putting "theFolder" in a string and then taking the lengh
of the string in my Substring call,

var s = @"theFolder\";
stemp = stemp.Substring(0,stemp.IndexOf(s)+s.Length)) + "afile.txt";

but wanted to see if there was an easier way?
There is for this type of task, use the methods of the Path class:
(add a "using System.IO;")

string stemp = Application.StartupPath;

string newFileName =
Path.Combine(Path.GetDirectoryName(stemp), "afile.txt");

Regards,
Gilles.

Jun 27 '08 #2
On May 23, 12:12*pm, "tshad" <ts...@dslextreme.comwrote:
IndexOf gives you the start of the string found in another string. *How do
you get the end of the string found?

I am trying to get the path of the startup:

string stemp = Application.StartupPath;

I then want to do something like:

stemp =
stemp.Substring(0,stemp.IndexOf(@"theFolder\")+Str ing.length((@"theFolder\"*))
+ "afile.txt";

So that I would end up with something like:

c:\folder1\theFolder\afile.txt

I could do this by putting "theFolder" in a string and then taking the lengh
of the string in my Substring call,

var s = @"theFolder\";
stemp = stemp.Substring(0,stemp.IndexOf(s)+s.Length)) + "afile.txt";

but wanted to see if there was an easier way?

Thanks,

Tom
Hi,

For working with files and folder you have a couple of classes like
Path , Directory and File
in your case Path.GetDirectoryName is what you are after I think
Jun 27 '08 #3

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

Similar topics

29
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return...
2
by: Badass Scotsman | last post by:
Hello, Using VB and ASP,NET I would like to be able to search a STRING for a smaller STRING within, based on the characters which appear before and after. For example: String1 = " That was...
6
by: Registered User | last post by:
Hi experts, I'm trying to write a program to solve the following exercise: Accept three strings from the user. Find the first occurrence of the first string in the third string. If it is present...
7
by: Adrian | last post by:
Why does std::strings find search from the begining of the string when pos >= (std::string::npos-3) I cant find anything in the standard that says what find should do if pos==npos in find I...
2
by: scoss04 | last post by:
Please can someone elp me with this peice of code below, i am trying to get the user to enter a an address, search through the string arrary address, if its found then stop if not found then get them...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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...
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.