C中字符串常见操作

#include  <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <wchar.h>
//	#include <stddef.h>
int main(void){
	char str1[]="This is the first string";
	char str2[]="That is the other string";

	//	printf(strcpy(str1,str2));//复制字符串

	//	printf(strncpy(str1,str2,20));//复制字符串指定长度内容

	//	printf("%d",strlen(str1));//字符串长度

    //	printf(strcat(str1,str2));//链接字符串

	//	printf(strncat(str1,str2,20));//链接指定长度字符串
	//
	//	printf("%d",strcmp(str1,str2));//比较字符串大小
	//
	//	printf("%d",strncmp(str1,str2,5));//比较指定长度的字符串大小

	//	char * pGot_char=strchr(str1,‘i‘);//搜索字符,返回找到字符的地址
	//	printf("%c",*pGot_char);//打印地址的内容

	//	if(strstr(str1,"the")==NULL){//搜索子串
	//		printf("no found");
	//	}
	//	else {
	//		printf("has found");
	//	}

	//	char buf[40];
	//	gets(buf);//将输入的字符串读入数组中,中间可以包含空格,直到回车,不同于scanf
	//	printf("%s",buf);

	//相比gets,fgets可以指定输入字符串最大长度
	//另外,gets只能用于标准输入流stdin,而fgets可以用于任意类型种类输入的字符串
	//在输入换行符时,fgets会存储一个‘\n‘字符,而gets不会。
	//	fgets(buf,sizeof(buf),stdin);
	//	printf("%s",buf);

	//atof字符串转double,atoi字符串转int
	//atol字符串转long,atoll字符串转longlong
	//	char value_str []="99.4";
	//	double value =atof(value_str);
	//	printf("%f",value);

	//宽字符串
	//	wchar_t proverb1[]=L"This is a wide type string";
	//	wchar_t proverb2[]=L"This is an other wide string";
	//	wchar_t wchar=L‘w‘;
	//	wchar_t wsring[]=L"wide";
	//	printf("%S\n",proverb1);//打印必须使用%S,而不是%s.
	//
	//	printf("%d\n",wcslen(proverb1));//宽字符串长度,不包含终止字符‘\0‘
	//
	//	wcscpy(proverb1,proverb2);//复制宽字符串
	//	wcsncpy(proverb1,proverb2,15);//复制指定长度
	//	wcscat(proverb1,proverb2);//连接宽字符串
	//	wcscmp(proverb1,proverb2);//比较大小
	//	wcsncmp(proverb1,proverb2,15);//比较指定长度的宽字符串大小
	//	wcschr(proverb1,wchar);//搜索宽字符
	//	wcsstr(proverb1,wsring);//搜索宽字符串

	wchar_t ina[80]=L"ss";
	fgetws(ina,sizeof(ina),stdin);//获取输入的宽字符串,指定了最大长度,和标准输入流
	printf("%S",ina);

	return 0;
}

C中字符串常见操作

时间: 2024-08-27 00:47:32

C中字符串常见操作的相关文章

.NET 字符串常见操作

1.取字符串长度   length string str="中国": int len=str.length; 2,字符串转化为比特码   GetBytes byte[] bytstr=system.Text.Encoding.Default.GetBytes(str); 3.字符串想家    stringBuilder() System.Text.StringBuilder sb=new System.text.StringBuilder(); sb.Append("中华&q

python字符串常见操作

字符串常见操作 如有字符串mystr = 'hello world itcast and itcastcpp',以下是常见的操作 <1>find 检测 str 是否包含在 mystr中,如果是返回开始的索引值,否则返回-1 mystr.find(str, start=0, end=len(mystr)) <2>index 跟find()方法一样,只不过如果str不在 mystr中会报一个异常. mystr.index(str, start=0, end=len(mystr)) &l

python基础--字符串常见操作

字符串常见操作 如有字符串mystr = 'hello world itcast and itcastcpp',以下是常见的操作 <1>find 检测 str 是否包含在 mystr中,如果是返回开始的索引值,否则返回-1 mystr.find(str, start=0, end=len(mystr)) <2>index 跟find()方法一样,只不过如果str不在 mystr中会报一个异常. mystr.index(str, start=0, end=len(mystr)) &l

javascript中字符串常用操作总结、JS字符串操作大全

字符串的操作在js中非常频繁,也非常重要.以往看完书之后都能记得非常清楚,但稍微隔一段时间不用,便会忘得差不多,记性不好是硬伤啊...今天就对字符串的一些常用操作做个整理,一者加深印象,二者方便今后温习查阅. String对象属性 (1) length属性 length算是字符串中非常常用的一个属性了,它的功能是获取字符串的长度.当然需要注意的是js中的中文每个汉字也只代表一个字符,这里可能跟其他语言有些不一样. var str = 'abc'; console.log(str.length);

D语言中字符串的操作

字符串的操作在软件开发中是特别重要的一个事情,因为基本上的编程都会使用到字符串,字符串操作的好坏决定着一个语言的好与差.在我做过的一个项目中曾经就出现过字符串操作性能问题. D语言字符串有 string,wstring,dstring三种类型,在D语言中字符串是使用字符数组定义的,三种类型分别对应char,wchar,dchar.char只有一个字节,wchar为双字节,dchar为三字节.对字符串的操作也相当于是对数组的操作,这跟其它语言不一样,C++中字符串是以string类来进行封装,它的

js--javascript中字符串常用操作总结、JS字符串操作大全

字符串的操作在js中非常频繁,也非常重要.以往看完书之后都能记得非常清楚,但稍微隔一段时间不用,便会忘得差不多,记性不好是硬伤啊...今天就对字符串的一些常用操作做个整理,一者加深印象,二者方便今后温习查阅. String对象属性 (1) length属性 length算是字符串中非常常用的一个属性了,它的功能是获取字符串的长度.当然需要注意的是js中的中文每个汉字也只代表一个字符,这里可能跟其他语言有些不一样. var str = 'abc'; console.log(str.length);

Python中字符串的操作

在python中字符串的包围的引号有三种,单引号,双引号,三引号,其中,单引号和双引号完全相同,在python中单引号也可完成转义工作 >>>print('doesn\'t \n it?') doesn't it? 但经常性的,一般使用 单双引号+转义更为普遍 >>>print("doesn't \n it?") doesn't  it? 三引号的使用,三引号(三个单引号或者三个双引号)用来座位注释,文档说明,类描述,用于比较广泛,他可以包含单引号,

字符串常见操作

如有字符串mystr = 'hello world loaderman and loadermancpp',以下是常见的操作 <1>find 检测 str 是否包含在 mystr中,如果是返回开始的索引值,否则返回-1 mystr.find(str, start=0, end=len(mystr)) Demo1 mystr = "hello world loaderman and loadermancpp" result= mystr.find("itcast&q

java String类-字符串常见操作

/* String常见的操作: String str="abchgthujidfg"; 1,获取 1.1字符串包含的字符数,即字符串的长度. int lenrth(): str.length();   //注意字符串获取长度的方法区别于数组获取长度的方法.数组采用格式:arr.length 1.2根据位置获取位置上的字符. char charAt(int index): str.charAt(4); 1.3根据字符获取该字符的位置. int indexOf(int ch): str.i