System.String.LastIndexOf problem

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2007
Posts: 68
Reputation: toadzky is an unknown quantity at this point 
Solved Threads: 0
toadzky toadzky is offline Offline
Junior Poster in Training

System.String.LastIndexOf problem

 
0
  #1
Mar 28th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: System.String.LastIndexOf problem

 
0
  #2
Mar 28th, 2007
Is your code in C++? Sounds like JavaScript
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 68
Reputation: toadzky is an unknown quantity at this point 
Solved Threads: 0
toadzky toadzky is offline Offline
Junior Poster in Training

Re: System.String.LastIndexOf problem

 
0
  #3
Mar 28th, 2007
I'm using VC++, Windows Forms App. I think its just C++ .NET.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: System.String.LastIndexOf problem

 
0
  #4
Mar 28th, 2007
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().
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 68
Reputation: toadzky is an unknown quantity at this point 
Solved Threads: 0
toadzky toadzky is offline Offline
Junior Poster in Training

Re: System.String.LastIndexOf problem

 
0
  #5
Mar 28th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1585 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC