473,402 Members | 2,053 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,402 software developers and data experts.

LastIndexOf

I am trying to check LastIndexOf "\" in a File Path, if it not there i want
to append a "\"

for some reason it throws error?

int index = filePath.LastIndexOf("\");

Any suggestions...

--
http://pathidotnet.blogspot.com
=====
vInAypAtHi
o__
---_,>/'_------
(_) \(_)
---------------
Feb 7 '07 #1
3 2625
"\\"

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"vinay" <vi***@discussions.microsoft.comwrote in message
news:B3**********************************@microsof t.com...
>I am trying to check LastIndexOf "\" in a File Path, if it not there i want
to append a "\"

for some reason it throws error?

int index = filePath.LastIndexOf("\");

Any suggestions...

--
http://pathidotnet.blogspot.com
=====
vInAypAtHi
o__
---_,>/'_------
(_) \(_)
---------------

Feb 7 '07 #2
Howdy,
public static string AppendDirSeparator(string path)
{
if (String.IsNullOrEmpty(path))
return String.Empty;

if (path[path.Length - 1] == System.IO.Path.DirectorySeparatorChar)
return path;
else
return path + System.IO.Path.DirectorySeparatorChar;
}
--
Milosz
"vinay" wrote:
I am trying to check LastIndexOf "\" in a File Path, if it not there i want
to append a "\"

for some reason it throws error?

int index = filePath.LastIndexOf("\");

Any suggestions...

--
http://pathidotnet.blogspot.com
=====
vInAypAtHi
o__
---_,>/'_------
(_) \(_)
---------------
Feb 7 '07 #3
you should modify your code like this:
int index = filePath.LastIndexOf("\\");

"vinay" <vi***@discussions.microsoft.comwrote in message
news:B3**********************************@microsof t.com...
>I am trying to check LastIndexOf "\" in a File Path, if it not there i want
to append a "\"

for some reason it throws error?

int index = filePath.LastIndexOf("\");

Any suggestions...

--
http://pathidotnet.blogspot.com
=====
vInAypAtHi
o__
---_,>/'_------
(_) \(_)
---------------
Feb 7 '07 #4

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

Similar topics

3
by: Jack-2 | last post by:
Hi! Three days ago I wrote in this group for ask help in the use of "GetDetailsOf". I want show the name of a file without the extension, and for this, a member of this group suggestion me that...
1
by: Matt | last post by:
In test() method: var path="C:\test\hello.txt"; //returns -1 for path.lastIndexOf("\\"). why?? var pos=path.lastIndexOf("\\"); //return -1 But in showFile() method: We are able to get the...
2
by: Ivar | last post by:
Hi, string s = "aXXa"; Console.WriteLine(s.LastIndexOf("XX",0)); Console.WriteLine(s.LastIndexOf("XX")); Console.WriteLine(s.IndexOf("XX",0)); Console.WriteLine(s.IndexOf("XX")); Result:...
9
by: sklett | last post by:
string url = http://localhost/subPath/Default.aspx; k = url.LastIndexOf("/", 0, url.Length); This throws an exception: Count must be positive and count must refer to a location within the...
3
by: Terry Olsen | last post by:
I have a string that is approximately 600 characters. I need to divide up the string into 400 character chunks. I'm having trouble with using LastIndexOf. The following code returns a value of...
0
by: ccshine via DotNetMonster.com | last post by:
I'm working on an app that implements a Structure to store a recordset in an ArrayList. I used this setup to bind to a DataGrid and it worked out so well, I thought it might be a better solution...
0
by: ccshine | last post by:
I'm working on an app that implements a Structure to store a recordset in an ArrayList. I used this setup to bind to a DataGrid and it worked out so well, I thought it might be a better solution...
9
by: senfo | last post by:
I realize it's Friday and I'm probably already on vacation for the remainder of the day; but, I have a really, really stupid question. Is there a bug in the .NET 2.0 Framework in regards to the...
3
by: Mathias Weyel | last post by:
Hi Group! I encounter a strange behaviour of String.LastIndexOf when specifying start and count values. The following works: string tempString = orgString.SubString(0, mycount); int index...
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: 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
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...
0
tracyyun
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.