Re-formatting a filename

This is a discussion on Re-formatting a filename within the Windows Programming forums, part of the Platform Specific Boards category; My question here is this. Lets say I store a filename into a CString, or an array. Then, I want ...

  1. #1
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644

    Re-formatting a filename

    My question here is this. Lets say I store a filename into a CString, or an array. Then, I want to find all the "_" or "-"'s in the filename, and with each one found, replace it w/ a " " (space)?

    When I searched this board, I couldn't come up with anything helpful.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    For the CString you would look at the CString documentation and find a likely method. I'd suggest something like Replace.

    For a normal char * string, you would loop through all the characters and replace as needed:
    Code:
    for (int i = 0;szFileName[i] != '\0';i++)
    {
        if (szFileName[i] == '_') szFileName[i] = ' ';
    }

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    3

    try this

    // c - the filename
    while ( *c )
    {
    if (*c == '_') *c = ' ';
    }
    Last edited by vito; 04-28-2004 at 02:46 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-11-2009, 02:49 AM
  2. Pass Filename to another function
    By awesmesk8er in forum C Programming
    Replies: 9
    Last Post: 10-24-2008, 02:43 PM
  3. adding line numbers and concatenating a filename
    By durrty in forum C Programming
    Replies: 25
    Last Post: 06-28-2008, 04:36 AM
  4. Replies: 3
    Last Post: 01-25-2006, 10:30 PM
  5. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 06:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21