Click to See Complete Forum and Search --> : manipulate system::string / string^


Dj_Saturn
December 27th, 2008, 07:54 PM
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.

TheCPUWizard
December 27th, 2008, 08:01 PM
Off the top of my head...NOT verified, but it should give you enough...


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...

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.

Dj_Saturn
December 27th, 2008, 09:09 PM
That definitely helped

status->Text = OpenedFileName->Substring(OpenedFileName->LastIndexOf('\\')+1);

this is how it was implemented.

Thanks!!!

TheCPUWizard
December 27th, 2008, 09:13 PM
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.

darwen
December 28th, 2008, 07:11 PM
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 ('http://msdn.microsoft.com/en-us/library/system.io.path.aspx') class functions e.g. Path::GetFileName, Path::GetDirectoryName etc.

It's got a really useful Combine ('http://msdn.microsoft.com/en-us/library/system.io.path.combine.aspx') method to add two paths together too.

Darwen.