944,135 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2123
  • C++ RSS
Mar 28th, 2007
0

System.String.LastIndexOf problem

Expand Post »
I am writing a program to batch rename files. I am trying to take the file name (which include folders) and remove everything before the last slash.

The problem is that LastIndexOf("\\") always returns -1, even if the string contains a "\".
And the Remove(0, index) doesn't ever remove any characters from the string.

If I were using std::strings, I would just use the findLastNotOf() and erase() functions.


TIA.
Last edited by toadzky; Mar 28th, 2007 at 4:43 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
toadzky is offline Offline
96 posts
since Mar 2007
Mar 28th, 2007
0

Re: System.String.LastIndexOf problem

Is your code in C++? Sounds like JavaScript
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007
Mar 28th, 2007
0

Re: System.String.LastIndexOf problem

I'm using VC++, Windows Forms App. I think its just C++ .NET.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
toadzky is offline Offline
96 posts
since Mar 2007
Mar 28th, 2007
0

Re: System.String.LastIndexOf problem

If you're using VC++ then using std::string is not problem !
C++ .NET -> I donno.
Reason why I said sounds like JavaScript is coz I googled the functions you'd posted and all links pointed to some JavaScript or the other.
Coming back to the problem, I'm sorry but without knowing teh function I can't comment. If you've spent enough time on this I suggest just implement your own find_first_of() and erase().
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007
Mar 28th, 2007
0

Re: System.String.LastIndexOf problem

Well, I fixed the LastIndexOf part. I finally realized that I was doing a search from back to front and the index I told it to start from was 0. So it never looked at the string.

That's working just fine, but the remove function still won't remove anything from the string.

TIA.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
toadzky is offline Offline
96 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help with indenting infile -> outfile paragraph...
Next Thread in C++ Forum Timeline: using borland C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC