CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2009
    Posts
    166

    just get filename from wstring?

    Hello,

    I have a file path in a wstring like this:

    wstring pathName = L"c:\windows\system\test.exe";

    I want to be able to geta new wstring that just contains "test" from this wstring.

    How can I do that? Can someone provide example code?

    Regards,
    Ellay K.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: just get filename from wstring?

    Quote Originally Posted by ekhule View Post
    Hello,

    I have a file path in a wstring like this:

    wstring pathName = L"c:\windows\system\test.exe";

    I want to be able to geta new wstring that just contains "test" from this wstring.

    How can I do that? Can someone provide example code?

    Regards,
    Ellay K.
    If you are using Windows, use the _tsplitpath function.

    Regards,

    Paul McKenzie

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: just get filename from wstring?

    Just iterate the string backwards till you find a slash, then iterate forwards saving the characters till you find a . What's the problem?

  4. #4
    Join Date
    Mar 2009
    Posts
    166

    Re: just get filename from wstring?

    Hello Paul,

    Do you have any sample code with that function? I can't much about it online.

    Regards,
    Ellay K.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: just get filename from wstring?

    Quote Originally Posted by ekhule View Post
    Hello Paul,

    Do you have any sample code with that function? I can't much about it online.

    Regards,
    Ellay K.
    _splitpath
    http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: just get filename from wstring?

    Quote Originally Posted by ekhule View Post
    Hello Paul,

    Do you have any sample code with that function? I can't much about it online.

    Regards,
    Ellay K.
    If you are only using wide chars, then _wsplitpath is the function.

    http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx
    http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx

    Regards,

    Paul McKenzie

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