C/C++字符串处理整合
来源:互联网 发布:淘宝上怎么卖电视棒 编辑:程序博客网 时间:2024/05/21 15:03
针对字符串的相关操作,空闲时,把之前的东西整理出来,供大家相互参考
/******************************************************************************************************
copyright (C),2015-2020,shijh .Co.,Ltd.FileName : string_manage.h
Author : Shijh Version : 1.0 Date: 2014年06月13日
Description : 字符串处理类
Version : 1.0
Function List:
1. static char* substr(const char*str, unsigned start, unsigned end) 从字符串的start到end截取end - start个字符
2. static char *left(char *dst, char *src, int n) 从字符串的左边截取n个字符
3. static char *right(char *dst, char *src, int n) 从字符串的右边截取n个字符
History :
<author> <time> <version> <desc>
Shijh 2014年06月13日 1.0 build this moudle
/******************************************************************************************************/
#ifndef __STRING_MANAGE_H__
#define __STRING_MANAGE_H__
#include <string.h>
#include <malloc.h>
class CStrManage
{
public:
/**************************************************************************************
Function : substr
Description : 从字符串的start到end截取end - start个字符
Calls : 对外部调用
Called By : 对字符串的中间字段的截取都要连接此函数
Input : const char*str, unsigned start, unsigned end
Output : dst
Return : char *
Author : Shijh Version : 1.0 Date: 2016年04月13日
Modify : 无
Others : 无
**************************************************************************************/
static char* substr(const char*str, unsigned start, unsigned end)
{
unsigned n = end - start;
char *dst = (char *)malloc(strlen(str) + 1);
strncpy(dst, str + start, n);
dst[n] = 0;
return dst;
}
/**************************************************************************************
Function : left
Description : 从字符串的左边截取n个字符
Calls : 对外部调用
Called By : 对字符串的左边字段的截取都要连接此函数
Input : char *dst, char *src, int n
Output : dst
Return : char *
Author : Shijh Version : 1.0 Date: 2016年04月13日
Modify : 无
Others : 无
**************************************************************************************/
static char *left(char *dst, char *src, int n)
{
char *p = src;
char *q = dst;
int len = strlen(src);
if (n > len) n = len;
while (n--) *(q++) = *(p++);
*(q++) = '\0'; /*有必要吗?很有必要*/
return dst;
}
/**************************************************************************************
Function : right
Description : 从字符串的右边截取n个字符
Calls : 对外部调用
Called By : 对字符串的右边字段的截取都要连接此函数
Input : char *dst, char *src, int n
Output : dst
Return : char *
Author : Shijh Version : 1.0 Date: 2016年04月13日
Modify : 无
Others : 无
**************************************************************************************/
static char *right(char *dst, char *src, int n)
{
char *p = src;
char *q = dst;
int len = strlen(src);
if (n > len) n = len;
p += (len - n); /*从右边第n个字符开始,到0结束*/
while (*(q++) = *(p++));
return dst;
}
}; // end CStrManage
#endif // end __STRING_MANAGE_H__
0 0
- C/C++字符串处理整合
- c中的字符串处理
- c++(字符串处理函数)
- 复习C字符串处理
- C字符串处理函数
- C字符串处理函数
- C语言字符串处理
- c 字符串处理
- C/C++字符串处理
- C 字符串处理
- c++(字符串处理函数)
- C字符串处理函数
- C字符串处理函数
- C字符串处理
- C字符串处理函数
- C- 字符串处理函数
- c 字符串处理函数
- C字符串处理函数
- VMWare CentOS无法联网
- web开发过程需要的知识网址收集
- Andriod下Amlogic开发环境搭建
- 【Android】Intent理解
- 设定email to case的准备工作和注意事项
- C/C++字符串处理整合
- 过滤器返回值
- css2.6_后代选择器
- 从I、B、P帧来解读DTS和PTS
- android4.4的设置菜单里面的系统默认配置
- new操作符返回null是否需要检测!!!
- 设置MySQL允许外网访问
- ubuntu 下运行程序报错 对‘std::cout’未定义的引用
- 实用小程序:C#读取Excel并根据每一条条目群发邮件(二)