manipulate system::string / string^ [resolved]
Ok,
i get the path of a file from an openfiledialog and assign it to string^ path.
so the string may contain for example...: c:/folder/example.mp3
from my knowledge you cannot manipulate a string but make a new one with your desired changes so ...
i want to remove everything before the last '/' and better yet, remove the last '/' as well
so i would be left with example.mp3
would i use the trim method?
if so please explain how to do so.
thank you very much.
Re: manipulate system::string / string^
Off the top of my head...NOT verified, but it should give you enough...
Code:
String s = "yada yada yada";
s = s.SubString(s.LastIndexOf('\')+1);
The kew point is that the manipulation routines RETURN a new string, so assigning it back to s will make that the "new value. Howeve...
Code:
String t = "yada yada yada";
s = t; // or passed to a method without "ref"...
s = s.SubString(s.LastIndexOf('\')+1);
Will NOT impact the value of t.
Re: manipulate system::string / string^
That definitely helped
Code:
status->Text = OpenedFileName->Substring(OpenedFileName->LastIndexOf('\\')+1);
this is how it was implemented.
Thanks!!!
Re: manipulate system::string / string^
Glad to help. Dont forget to mark threads as resolved, and to rate (using the scales displayed to the right of the reply) those who helped.
Re: manipulate system::string / string^
I'm a bit late on this one but :
If you're doing string manipulations on filenames it's better to use the System::IO::Path class functions e.g. Path::GetFileName, Path::GetDirectoryName etc.
It's got a really useful Combine method to add two paths together too.
Darwen.