首页 > 编程知识 正文

c++字符串常用函数,c语言常用字符串处理函数

时间:2023-05-05 20:22:40 阅读:178757 作者:4503

1. strcat函数字符串连接函数

# include ' stdio.h ' # include ' string.h '//strcat函数。 int main () charstr1(30 )={'Hello'},str2)={'word.'}; printf('%s”,strcat ) str2,str2); //strcat(a字符数组、b字符数组); } //strcat函数--字符串连接函数//a字符数组必须足够大以存储后续的新字符串。

2.strcpy和strncpy函数字符串复制函数。

# include stdio.h # include string.h/strcpy和strncpy函数int main ((为了使用char str (20 )=(1234567890 ) )={ ' } //一般类型strcpy (字符数组、字符串); 角色:将字符串复制到字符数组。 strcpy(b,' world ' ); strncpy(d,a,2; //角色将a中的前两个字符复制到字符数组d中,使字符数组d后面的保持不变。 puts(str; puts(b ); puts(d ); }

3.strcmp函数字符串比较函数

# include stdio.h # include string.h//strcmp (字符数组1,字符数组2 ); 第一个不同字符的ASCII代码int main () chara ) )={'happy'},b )={'help'},c )={'happy'}; printf(%d(n ),strcmp(a ) a,b ); //'a' 'e '函数的值为负数的printf(%dn ),strcmp(b ) b,a ); printf(%d(n ),strcmp(a ) ) a,c ); //所有字符中相同的函数值为0 }

4.strlen函数测字符串长度的函数。

作用:测量字符串的长度

函数值是字符串的实际长度。 不包括“ 0”。

# include ' stdio.h ' # include ' string.h ' int main () {char a[10]={'12345'}; printf('%dn ',strlen(a ) ); printf(%d(n ),strlen ) ) he ); }

5.strlwr和strupr函数---大小写转换函数

# include ' stdio.h ' # include ' string.h ' int main () chara[]=(abcdefgh ); puts(strlwr(a ) ); //strlwr函数将字符串的大小写转换为小写。 puts(strupr(a ) ); //strupr函数将字符串的小写字母转换为大写字母。 }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。