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.


Is your code in C++? Sounds like JavaScript

I'm using VC++, Windows Forms App. I think its just C++ .NET.

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(). :)

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.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.