|
-
December 27th, 2008, 07:54 PM
#1
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.
Last edited by Dj_Saturn; December 27th, 2008 at 09:11 PM.
Reason: resolved
-
December 27th, 2008, 08:01 PM
#2
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.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
December 27th, 2008, 09:09 PM
#3
Re: manipulate system::string / string^
That definitely helped
Code:
status->Text = OpenedFileName->Substring(OpenedFileName->LastIndexOf('\\')+1);
this is how it was implemented.
Thanks!!!
-
December 27th, 2008, 09:13 PM
#4
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.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
December 28th, 2008, 07:11 PM
#5
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|