LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Basic String Manipulation Question

I have this  c:\test\basic\testfile.xls

and I want testfile.xls extracted string.

 

I did it the hard way and wrote my own function

 

void ConvertFilename( char *path, int count)

char tmp[MAX_FILE_CHAR];
int found =0,i=0,j=0;
                
    for (i=0; i < count; i++)
    {
     tmp[i]= (( char ) *path++ );
       
     if ( tmp[i] == '\\' ) found = i;
    }


    for (j=found; j < count; j++) *(path ++) = tmp[j];
    
 *(path ++) = 0;

Is there an easier way in CVI?

Thanks

0 Kudos
Message 1 of 6
(3,653 Views)
There is SplitPath() in the utility library
0 Kudos
Message 2 of 6
(3,648 Views)
there is also the Shell Lightweight API library, which is part of the Windows SDK. add "shlwapi.lib" into your project and #include "shlwapi.h" from your source file. in this library, the path manipulation function generally starts with the word Path. for example, PathCombine() is the function to merge 2 pathes together.
0 Kudos
Message 3 of 6
(3,642 Views)

Or you could also just use the C string manipulation basics:

 

char *lastSep= strrchr(path, '\\');

return lastSep ? ++lastSep : path;

 

Mert A.

National Instruments 

 

 

0 Kudos
Message 4 of 6
(3,637 Views)
(a little note: although this is the simplest and most efficient implementation, you should never ever roll your own path manipulation function, because you will always forget one or another not-so-special case)
0 Kudos
Message 5 of 6
(3,609 Views)

Markus, excellent suggestion, works great !!

 

Thank U all

 

Diego

0 Kudos
Message 6 of 6
(3,604 Views)