字符/字符串操作函数(C)
来源:互联网 发布:身高数据呈现 编辑:程序博客网 时间:2024/05/17 07:00
isdigit
Tests whether an element in a locale is a numeric character.
检查指定元素是否是数字
原型:
template
bool isdigit(
CharType _Ch,
const locale& _Loc //国家–语种
)
示例:
include
include
using namespace std;
int main( )
{
locale loc ( “German_Germany” );
bool result1 = isdigit ( ‘L’, loc );//false
bool result2 = isdigit ( ‘@’, loc );//false
bool result3 = isdigit ( ‘3’, loc );//true
}
isalpha
//检测指定函数是否是字母 用法,原型同上
isalnum
//检测指定函数是否是字母或者数字,用法、原型同上
toupper、tolower
toupper:把指定元素转成大写
tolower:把指定元素转成小写
原型:
template
CharType toupper(
CharType _Ch,
const locale& _Loc
)
示例:
int main( )
{
locale loc ( “German_Germany” );
char result1 = toupper ( ‘h’, loc );//H
char result2 = toupper ( ‘H’, loc );//H
char result3 = toupper ( ‘
}
同理,tolower
sprintf_s
//格式化一个字符串,比sprintf更加安全。
//示例
char buffer[20];
int a = 2, b = 3;
sprintf_s(buffer, _countof(buffer), TEXT(“加法:%d+%d=%d”), a, b, a + b);
atoi | atof
字符串转成整数或者浮点数
char buf[] = “1234578”;
int nNum=atoi(buf);//1234578
float nFloat = atof(buf); //1234578.00
strlen
//返回指定字符串的实际长度,不包括‘\0’;
int i = strlen(str1);
strcpy_s
//复制字符串
errno_t strcpy_s(
char *strDestination,//目标
size_t numberOfElements,//目标缓冲区的大小
const char *strSource //源
);
//示例
include
strcmp
int strcmp(
const char *string1,
const char *string2
);
//比较两个字符串是否相等
strstr
//在一个字符串中查找另一个字符串并返回目标地址
char *strstr(
const char *str,
const char *strSearch
); // C only
strtok_s
//用指定的标志来分割字符串
原型:
char *strtok_s(
char *strToken, //需要分割的字符串
const char *strDelimit,//用什么来做这个分割标记
char **context //out 指向剩下的字符串
);
示例:
// crt_strtok_s.c// In this program, a loop uses strtok_s// to print all the tokens (separated by commas// or blanks) in two strings at the same time.//#include <string.h>#include <stdio.h>char string1[] = "A string\tof ,,tokens\nand some more tokens";char string2[] = "Another string\n\tparsed at the same time.";char seps[] = " ,\t\n";char *token1 = NULL;char *token2 = NULL;char *next_token1 = NULL;char *next_token2 = NULL;int main( void ){ printf( "Tokens:\n" ); // Establish string and get the first token: token1 = strtok_s( string1, seps, &next_token1); token2 = strtok_s ( string2, seps, &next_token2); // While there are tokens in "string1" or "string2" while ((token1 != NULL) || (token2 != NULL)) { // Get next token: if (token1 != NULL) { printf( " %s\n", token1 ); token1 = strtok_s( NULL, seps, &next_token1); } if (token2 != NULL) { printf(" %s\n", token2 ); token2 = strtok_s (NULL, seps, &next_token2); } }}
_strupr_s
//把字串转成大写
原型:
errno_t _strupr_s(
char *str,
size_t numberOfElements
);
示例:
char string1[] =”A string\tof ,,tokens\nand some more tokens”;
_strupr_s(string1, sizeof(string1));
//全部转成大写字母显示
_strlwr_s
//把字串转成小写
用法与原型同上。
- 字符/字符串操作函数(C)
- c 字符操作函数
- c 字符操作函数
- 标准c字符和字符串操作 atof() 函数
- 字符及字符串操作函数
- 字符及字符串操作函数
- c字符和字符串操作
- C字符串操作函数
- C字符串操作函数
- C字符串操作函数
- c 字符串操作函数
- C--字符串操作函数
- C 字符/字符串常用函数
- 字符和字符串C函数
- C-常用字符操作函数
- 字符串处理函数、字符操作函数
- C语言字符和字符串操作
- C语言字符串操作函数
- sql server附加数据库错误的解决方法
- oracle利用flashback 闪回功能恢复delete数据
- Docker Swarm中使用TLS
- Ubuntu日记——ubuntu中无法识别android手机问题
- Centos7安装Jenkins
- 字符/字符串操作函数(C)
- the operation couldn't be completed.
- HDU 2059 龟兔赛跑
- jquery源码分析—data缓存
- 【QT学习】解决对话框的中文字符串乱码
- unity 代码设置要打包的AssetBundle
- Spring 中的SpEL
- 文本特征提取
- 创建型模式————工厂方法模式