Thread: Re-formatting a filename

  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 01:46 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-11-2009, 01:49 AM
  2. Pass Filename to another function
    By awesmesk8er in forum C Programming
    Replies: 9
    Last Post: 10-24-2008, 01:43 PM
  3. adding line numbers and concatenating a filename
    By durrty in forum C Programming
    Replies: 25
    Last Post: 06-28-2008, 03: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