C++ 字符串操作常见函数
//字符串拷贝,排除指定字符
char *strcpy_exclude_char(char *dst, const int dst_len, const char *src, const char *exclude_list)
{
int i = , j = , flag = ;
const char *p = NULL;
if (dst == NULL && src == NULL)return NULL;
if (dst == src)return dst;
for (; j < dst_len && src[i] != '\0'; ++i)
{
flag = ;
p = exclude_list;
while (p && *p != '\0')
{
if (*p == src[i]){ flag = ; break; }
p++;
}
if (flag == )dst[j++] = src[i];
}
dst[j] = '\0';
return dst;
}
//字符串拷贝,替换指定字符
char *strcpy_replace_char(char *dst, const int dst_len, const char *src, char aim, char rep)
{
int i = ;
if (dst == NULL && src == NULL)return NULL;
if (dst == src)return dst;
for (; i < dst_len && src[i] != '\0'; ++i)
{
if (src[i] == aim)
{
dst[i] = rep;
}
else
{
dst[i] = src[i];
}
}
dst[i] = '\0';
return dst;
}
//字符串原址替换指定字符
char * str_replace_char(char *dst, char aim, char rep)
{
int i = ;
if (dst == NULL)return NULL;
for (; dst[i] != '\0';++i)
{
if (dst[i] == aim)
{
dst[i] = rep;
}
}
return dst;
}
C++ 字符串操作常见函数的更多相关文章
- python学习笔记(字符串操作、字典操作、三级菜单实例)
字符串操作 name = "alex" print(name.capitalize()) #首字母大写 name = "my name is alex" pri ...
- shell编程常用的截取字符串操作
1. 常用的字符串操作 1.1. 替换字符串:$ echo ${var/ /_}#支持正怎表达式 / /表示搜索到第一个替换,// /表示搜索到的结果全部替换. ...
- php字符串操作集锦
web操作, 主要就是对字符文本信息进行处理, 所以, 字符串操作几乎占了很大一部分的php操作.包括 注意strstr 和 strtr的区别? 前者表示字符串查找返回字符串,后者表示字符串中字符替换 ...
- java 字符串操作和日期操作
一.字符串操作 创建字符串 String s2 = new String("Hello World"); String s1 = "Hello World"; ...
- [No000078]Python3 字符串操作
#!/usr/bin/env python3 # -*- coding: utf-8 -*- '''Python 字符串操作 string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分 ...
- Python 字符串操作及string模块使用
python的字符串操作通过2部分的方法函数基本上就可以解决所有的字符串操作需求: python的字符串属性函数 python的string模块 1.字符串属性方法操作: 1.>字符串格式输出对 ...
- C语言字符串操作总结大全
1)字符串操作 strcpy(p, p1) 复制字符串 函数原型strncpy(p, p1, n) 复制指定长度字符串 函数原型strcat(p, p1) 附加字符串 函数原型strn ...
- c# 字符串操作
一.字符串操作 //字符串转数组 string mystring="this is a string" char[] mychars=mystring.ToCharArray(); ...
- C语言字符串操作总结大全(超详细)
本篇文章是对C语言字符串操作进行了详细的总结分析,需要的朋友参考下 1)字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strcat( ...
随机推荐
- js:语言精髓笔记2--表达式
表达式:由运算符和运算元构成:JS中没有运算符的表达式称为单值表达式:没有运算元,孤立与代码上下文的运算符是不符合语法的:(表达式是有返回值的) 单值表达式: this引用: 变量引用: 直接量: n ...
- js:语言精髓笔记1--标识符与基本类型
标识符: 命名: 语法以及类型----语法关键字 //逻辑 值(的存储位置)----变量和常量 ...
- C# 使用 Direct2D 实现斜角效果
Direct2D 是微软新的二维图形 API,可为二维几何图形.位图和文本提供高性能和高质量的呈现.Direct2D 支持硬件加速,无论是绘制速度还是绘制质量,Direct2D 都要比 GDI 和 G ...
- python 代码片段14
#coding=utf-8 #enumerate是一个内置函数 data=(123,'abc',3.14) for i,value in enumerate(data): print i,value
- BZOJ1077 : [SCOI2008]天平
首先通过差分约束系统建图,用Floyed算法求出任意两个砝码差值的上下界. 然后暴力枚举放在右边的砝码C,D,通过与A,B差值的上下界分类讨论统计方案. 时间复杂度$O(N^3)$. #include ...
- HDU 4405 期望DP
期望DP算是第一题吧...虽然巨水但把思路理理清楚总是好的.. 题意:在一个1×n的格子上掷色子,从0点出发,掷了多少前进几步,同时有些格点直接相连,即若a,b相连,当落到a点时直接飞向b点.求走到n ...
- #region 自适应屏幕分辨率
#region 自适应屏幕分辨率 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public ...
- Dijkstra堆优化与SPFA模板
Dijkstra+优先队列 #include<cstdio> #include<cctype> #include<queue> #include<cstrin ...
- u盘文件系统故障的修复方法
比如U盘挂载的文件系统是/dev/sda1,且文件系统有故障(FAT: Filesystem error) 修复U盘文件系统故障 sudo dosfsck -v -a /dev/sda1
- HTML中为何P标签内不可包含DIV标签?
起因:在做项目时发现原本在DW中无误的代码到了MyEclipse6.0里面却提示N多错误,甚是诧异.于是究其原因,发现块级元素P内是不能嵌套DIV的. 深究:我们先来认识in-line内联元素和blo ...