C/C++ 知识点---字符串函数
1.strcpy字符串拷贝
2.strcmp字符串比较
3.strstr字符串查找
4.strDelChar字符串删除字符
5.strrev字符串反序
6.memmove拷贝内存块
7.strlen字符串长度
---------------------------------------
1.strcpy字符串拷贝
拷贝pStrSource到pStrDest,并返回pStrDest地址(源和目标位置重叠情况除外)
char *strcpy(char *pStrDest, const char *pStrSource)
{
assert(NULL!=pStrDest && NULL!=pStrSource);
char *strTemp=pStrDest;
while ((*pStrDest++ = *pStrSource++) != '\0'); return strTemp;
}
2.strcmp字符串比较
int strcmp(const char *pStrA, const char *pStrB)
{
assert(NULL!=pStrA && NULL!=pStrB);
while (*pStrA && *pStrB && *pStrA==*pStrB)
{
++pStrA;
++pStrB;
} return (pStrA-*pStrB);
}
3.strstr字符串查找
char *strstr(const char *pStrSource, const char *pStrSearch)
{
assert(pStrSource != NULL && pStrSearch != NULL);
const char *strTempSource = pStrSource;
const char *strTempSearch = pStrSearch;
for (; *pStrSource!='\0'; ++pStrSource)
{
for (strTempSource=pStrSource,strTempSearch=pStrSearch;
*strTempSearch!='\0' && *strTempSearch==*strTempSource;
++strTempSource, ++strTempSearch); if (*strTempSearch == '\0')
{
return (char *)pStrSource;
}
} return (char *)NULL;
}
4.strDelChar字符串删除字符
char *strDelChar(char *pStrSource, const char chDel)
{
assert(NULL!=pStrSource && !isspace(chDel));
char *pTempStrA, *pTempStrB;
pTempStrA = pTempStrB = pStrSource; while (*pTempStrB++)
{
if (*pTempStrB != chDel)
{
*pTempStrA++ = *pTempStrB;
}
}
*pTempStrA = '\0'; return pStrSource;
}
5.strrev字符串反序
char *strrev(char *pStrSource)
{
assert (NULL != pStrSource); char *pStrStart, *pStrEnd;
pStrStart = pStrEnd = pStrSource;
while (*pStrEnd != '\0')
{
++pStrEnd;
} char chTemp;
for (--pStrEnd, pStrStart; pStrEnd<pStrStart; ++pStrStart, --pStrEnd)
{
chTemp = *pStrStart;
*pStrStart = *pStrEnd;
*pStrEnd = chTemp;
} return pStrSource;
}
6.memmove拷贝内存块
void *memmove(void *pStrTo, const void *pStrFrom, size_t count)
{
assert (NULL!=pStrTo && NULL!=pStrFrom); void *pStrRet = pStrTo; if (pStrTo<pStrFrom || pStrTo>pStrFrom+count-)
{
//内存块不重叠情况
while (count--)
{
*pStrTo++ = *pStrFrom++;
}
}
else
{
//内存块重叠情况
char *pStrDest = (char *)pStrTo;
char *pStrSource = (char *)pStrFrom;
pStrDest = pStrDest+count-;
pStrSource = pStrSource+count-;
while (count--)
{
*pStrDest-- = *pStrSource--;
}
} return pStrRet;
}
7.strlen字符串长度
int strlen(const char *pStrSource)
{
assert(NULL != pStrSource);
int iLen = ;
while (*pStrSource++ != '\0')
{
++iLen;
} return iLen;
}
C/C++ 知识点---字符串函数的更多相关文章
- ThinkPHP 模板substr的截取字符串函数
ThinkPHP 模板substr的截取字符串函数在Common/function.php加上以下代码 /** ** 截取中文字符串 **/ function msubstr($str, $start ...
- SQL字符串函数
LEN() :计算字符串长度(字符的个数.)datalength();//计算字符串所占用的字节数,不属于字符串函数.测试varchar变量与nvarchar变量存储字符串a的区别.见备注1.LOWE ...
- Python3中的字符串函数学习总结
这篇文章主要介绍了Python3中的字符串函数学习总结,本文讲解了格式化类方法.查找 & 替换类方法.拆分 & 组合类方法等内容,需要的朋友可以参考下. Sequence Types ...
- TSQL 字符串函数:截断和查找
字符串截断函数是指:Stuff 和 SubString,字符串查找函数是:CharIndex 和 PatIndex 一,SubString 截取子串 最常用的字符串函数,用于截取特定长度的子串. SU ...
- c#编程基础之字符串函数
c#常用的字符串函数 例一: 获取字符串的大小写函数 ToLower():得到字符串的小写形式 ToUpper():得到字符串的大写形式 注意: 字符串时不可变的,所以这些函数都不会直接改变字符串的内 ...
- SQLSERVER常见系统函数之字符串函数(一)
好久没有写博客了,这段时间准备写一下字符串函数 QQ群: 499092562:欢迎交流 字符串函数: 1.LEN(需要获取长度的字符串) 返回:字符串的长度 示例: SELECT LEN('小搬运工很 ...
- python笔记-字符串函数总结
字符串函数: chr() 数字转ASCII chr(96)="a" ord() ASCII转数字 ord("a")=96 isspace() 判断是否为空格 s ...
- Sql Server函数全解<一>字符串函数
阅读目录 1.ASCII()函数 2.CHAR()函数 3.LEFT()函数 4.RIGHT()函数 5.LTRIM()函数 6.RTRIM()函数 7.STR()函数 8.字符串逆序的函数REVER ...
- Sql Server系列:字符串函数
字符串函数用于对字符和二进制字符串进行各种操作,大多数字符串函数只能作用于char.nchar.varchar和nvarchar数据类型.字符串函数可以用在SELECT或者WHERE语句中. 1. A ...
随机推荐
- Python3控制结构与函数
1.if语句的另一种写法: expression1 if boolean_expression else expression2 boolean_expression为true时使用expressio ...
- jsPlumb之流程图项目总结及实例
在使用jsPlumb过程中,所遇到的问题,以及解决方案,文中引用了<数据结构与算法JavaScript描述>的相关图片和一部分代码.截图是有点多,有时比较懒,没有太多的时间去详细的编辑. ...
- React--JSX语法
JSX语法,它是js语言的语法拓展. 比如2+2 , 对象.属性 , 函数的调用都可以在jsx中书写. import React from "react"; export defa ...
- AngularJS 和 Bootstrap
AngularJS Bootstrap AngularJS 的首选样式表是 Twitter Bootstrap, Twitter Bootstrap 是目前最受欢迎的前端框架. 查看 Bootstra ...
- JavaScript一个集合的运算类
输出都在控制台中: <script type="text/javascript"> function Set() { //这是一个构造函数 this.values = ...
- Exception in thread "http-bio-8080-exec-2" java.lang.OutOfMemoryError: PermGen space[解决方案]
- innodb关键特性之double write
# 脏页刷盘的风险 两次写的原理机制 1.解决问题 2.使用场景 3.doublewrite的工作流程 4.崩溃恢复 # doublewrite的副作用 1.监控doublewrite负载 2.关闭d ...
- (转) Eclipse Maven 编译错误 Dynamic Web Module 3.1 requires Java 1.7 or newer 解决方案
场景:在导入Maven项目时候遇到如下错误. 1 问题描述及解决 Eclipse Maven 开发一个 jee 项目时,编译时遇到以下错误:Description Resource Path Loca ...
- (转)Java并发编程:Callable、Future和FutureTask
Java并发编程:Callable.Future和FutureTask 在前面的文章中我们讲述了创建线程的2种方式,一种是直接继承Thread,另外一种就是实现Runnable接口. 这2种方式都有一 ...
- 【css】过度效果
http://kissygalleryteam.github.io/girlLink/doc/demo/index.html