CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2008
    Posts
    19

    Exclamation 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

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    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

  3. #3
    Join Date
    Oct 2008
    Posts
    19

    Re: manipulate system::string / string^

    That definitely helped

    Code:
    status->Text = OpenedFileName->Substring(OpenedFileName->LastIndexOf('\\')+1);
    this is how it was implemented.

    Thanks!!!

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    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

  5. #5
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    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.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

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
  •  





Click Here to Expand Forum to Full Width

Featured