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( ...
随机推荐
- 递推DP URAL 1260 Nudnik Photographer
题目传送门 /* 递推DP: dp[i] 表示放i的方案数,最后累加前n-2的数字的方案数 */ #include <cstdio> #include <algorithm> ...
- 跳舞毯[XDU1005]
Problem 1005 - 跳舞毯 Time Limit: 2000MS Memory Limit: 65536KB Difficulty: Total Submit: 308 Accep ...
- BZOJ4297 : [PA2015]Rozstaw szyn
每个点的最优取值范围是一个区间,将叶子一层层剥去,得到一棵有根树,父亲的取值范围由儿子推得,时间复杂度$O(n\log n)$. #include<cstdio> #include< ...
- BZOJ3775 : 点和直线
设第$i$条直线的解析式为$a_ix+b_iy+c_i=0$,$d_i=a_i^2+b_i^2$,则要求一个点$(x,y)$,使得$\sum\left(\frac{\left|a_ix+b_iy+c_ ...
- chrome developer tool 调试技巧
这篇文章是根据目前 chrome 稳定版(19.0.1084.52 m)写的, 因为 google 也在不断完善chrome developer tool, 所以 chrome 版本不同可能稍有差别. ...
- 升级到WP8必需知道的13个特性
http://www.cnblogs.com/sonic1abc/archive/2012/11/28/2792467.html Windows phone 8 SDK 已经发布一段时间了, 已经 ...
- BZOJ3925: [Zjoi2015]地震后的幻想乡
Description 傲娇少女幽香是一个很萌很萌的妹子,而且她非常非常地有爱心,很喜欢为幻想乡的人们做一些自己力所能及的事情来帮助他们. 这不,幻想乡突然发生了地震,所有的道路都崩塌了.现在的首要任 ...
- try {}里有一个return语句,那么紧跟在这个try后的finally {}里的code会不会被执行,什么时候被执行,还是在return之后执行?
这是一个很有趣的问题,我测试的结果是:是在return中间执行. 我在网上搜寻了一些资料,下面是参考代码: /** * */ package com.b510.test; /** * try {}里有 ...
- IntelliJ IDEA 14 SVN无法正常使用问题
通过SVN导入项目 SVN checkout时候会出现如下错误: Cannot run program "svn" (in directory "E:\Projects& ...
- NHibernate's inverse - what does it really mean?
NHibernate's concept of 'inverse' in relationships is probably the most often discussed and misunder ...