Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Get the length of the path (not the filename)

Get the length of the path (not the filename)

Scheduled Pinned Locked Moved The Weird and The Wonderful
6 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eric Haddan
    wrote on last edited by
    #1

    Gets the offset of the last backslash of a path. :omg: Enjoy!!

    int PathLen( LPCWSTR sWholePath)
    {
    CString sTmp(sWholePath),sTmp2;
    int iPos=sTmp.Find('\\'),iStart=iPos+1;
    while(1)
    {
    sTmp2=sTmp.Mid(iStart);
    iPos=sTmp2.Find('\\');
    if(iPos >= 0)
    iStart+=(iPos+1);
    else
    break;
    };
    return iStart;
    };

    P S 2 Replies Last reply
    0
    • E Eric Haddan

      Gets the offset of the last backslash of a path. :omg: Enjoy!!

      int PathLen( LPCWSTR sWholePath)
      {
      CString sTmp(sWholePath),sTmp2;
      int iPos=sTmp.Find('\\'),iStart=iPos+1;
      while(1)
      {
      sTmp2=sTmp.Mid(iStart);
      iPos=sTmp2.Find('\\');
      if(iPos >= 0)
      iStart+=(iPos+1);
      else
      break;
      };
      return iStart;
      };

      P Online
      P Online
      PIEBALDconsult
      wrote on last edited by
      #2

      Bah! Go recursive! :-D

      1 Reply Last reply
      0
      • E Eric Haddan

        Gets the offset of the last backslash of a path. :omg: Enjoy!!

        int PathLen( LPCWSTR sWholePath)
        {
        CString sTmp(sWholePath),sTmp2;
        int iPos=sTmp.Find('\\'),iStart=iPos+1;
        while(1)
        {
        sTmp2=sTmp.Mid(iStart);
        iPos=sTmp2.Find('\\');
        if(iPos >= 0)
        iStart+=(iPos+1);
        else
        break;
        };
        return iStart;
        };

        S Offline
        S Offline
        Stanciu Vlad
        wrote on last edited by
        #3

        I think you guy has read a book about algorithms and optimizing them – overzealous with a weird way of thinking. “I go through the string from the first char through all the backslashes until there aren’t any” instead of “I go through the string from the last char until there is a backslash” Or maybe he was just trying to make things harder for anyone else that would look at the code... :laugh:

        I have no smart signature yet...

        W M 2 Replies Last reply
        0
        • S Stanciu Vlad

          I think you guy has read a book about algorithms and optimizing them – overzealous with a weird way of thinking. “I go through the string from the first char through all the backslashes until there aren’t any” instead of “I go through the string from the last char until there is a backslash” Or maybe he was just trying to make things harder for anyone else that would look at the code... :laugh:

          I have no smart signature yet...

          W Offline
          W Offline
          WiGgLr
          wrote on last edited by
          #4

          or he hasn't heard of the LastIndex string method O_o

          P 1 Reply Last reply
          0
          • W WiGgLr

            or he hasn't heard of the LastIndex string method O_o

            P Online
            P Online
            PIEBALDconsult
            wrote on last edited by
            #5

            LastIndex is only more efficient if you already know how long the string string is. In C, that would have to scan the entire string and then back up, which is less efficient.

            1 Reply Last reply
            0
            • S Stanciu Vlad

              I think you guy has read a book about algorithms and optimizing them – overzealous with a weird way of thinking. “I go through the string from the first char through all the backslashes until there aren’t any” instead of “I go through the string from the last char until there is a backslash” Or maybe he was just trying to make things harder for anyone else that would look at the code... :laugh:

              I have no smart signature yet...

              M Offline
              M Offline
              Michael J Eber
              wrote on last edited by
              #6

              Ohhhh, I've known many developers that write code harder because they think it looks cool. Unfortunately I've known WAY too many especially this fat pig that preached about how website development is very difficult; he then went on to develop a very difficult website. Mike's code was soooooooo bad that they have to run to instances of the website on the same machine to properly test it....according to him. He was also complaining about how hard it was to test his code after his iterative code went more than 30 levels deep.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups