字符串常用操作集锦


1. 字符串拼接
#define VERSION_DESC(name, author, date, extra) #name"_"#author"_v"#date"_"#extra

2. 去除目录文件前面的目录

复制代码
#include <stdio.h>
#include <string.h>

#define DIR_FILE    "/tmp/xxx/test"
int main()
{
    char *file;

    if(strrchr(DIR_FILE, '/'))
        file = strrchr(DIR_FILE, '/') + 1;
    
    printf("dir_file-> file [%s]
", file);

    if(strrchr(file, '/'))
        file = strrchr(DIR_FILE, '/') + 1;
    
    printf("file-> file [%s]
", file);

    return 0;
}
复制代码

运行结果

dir_file-> file [test]
file-> file [test]
原文地址:https://www.cnblogs.com/embedded-linux/p/6012386.html