C语言 unicode 字符串处理Demo

发布时间:2024年01月24日

概述

? ? ? ? 做个笔录

1、示例1

#include <stdio.h>
#include <string.h>
#include "main.h"

struct strStruct
{
	uint16_t phone_num[16];
	uint16_t message[400];
};

void filterSpaces(char* src, char* dst)
{
	uint8_t i = 0;
	uint8_t flag = 0;
	char* p = NULL;	

	for (p = src; *p != '\0'; p++) {
		if (*p == ':') {
			flag = 1;	//android
		}
		if (*p == ' ') {
			flag = 2;	//ios
		}
	}

	/* andorid */
	if (flag == 1) {
		for (p = src; *p != ':'; p++) {
			/*if (*p == ':') {
				break;
			}*/
			dst[i++] = *p;
		}
	}

	/* ios */
	if (flag == 2) {
		/* p=str indicates that the pointer points to the first address of the string to mark */
		for (p = src; *p != '\0'; p++) {
			/* Not equal to '\0' means p++ as long as the string does not end. */
			if (*p != ' ') {
				dst[i++] = *p;
			}
		}
	}

}


int main(void)
{
	struct strStruct str, str1;
	memcpy(str.phone_num, "13578942356", sizeof("13578942356"));
//	memcpy(str.message, "135 7894 2356", sizeof("135 7894 2356"));
	memcpy(str.message, "来来来:13578942356", sizeof("13578942356"));

	printf("111 %s, %s\n", (char*)str.message, (char*)str1.message);

	filterSpaces((char*)str.message, (char*)str1.message);
	printf("222 %s, %s\n", (char*)str.message, (char*)str1.message);
	int res = strcmp((char*)str1.message, (char*)str.phone_num);
//	char* res = strstr((char*)str1.message, (char*)str.input_num);


	if (res == 0)
	//if (res != NULL)
	{
		printf("两个字符串相等!");
	}
	else 
	{
		printf("两个字符串不相等!");
	}

	printf("heihei");
}

2、示例2:?

#include <stdio.h>
#include <string.h>
#include "main.h"

struct strStruct
{
	uint16_t phone_num[16];
	uint16_t message[400];
};

uint8_t filterSpacesColon(uint16_t* src, uint16_t* dst)
{
	uint8_t index = 0;
	uint8_t flag = 0;
	uint16_t* p = src;		
	
	while(*p != '\0')
	{
		if (*p == ':') {
			flag = 1;	//android
			break;
		}
		if (*p == ' ') {
			flag = 2;	//ios
			break;
		}
		p++;
	}
	
	/* andorid */
	if (flag == 1) {
		for (p = src; *p != '\0'; p++, dst++) {
			if (*p == ':') {
				break;
			}
			*dst = *p;
			index++;
		}
	}

	/* ios */
	if (flag == 2) {
		/* p=str indicates that the pointer points to the first address of the string to mark */
		for (p = src; *p != '\0'; p++) {
			/* Not equal to '\0' means p++ as long as the string does not end. */
			if (*p != ' ') {
				dst[index++] = *p;
			}
		}
	}
	
	return index;
}	

int main(void)
{
    filterSpacesColon(str.message, message);
    printf("222 %s, %s\n",str.message, message);
	for (int i = 0; i < 32; i++)
	{
		printf("0x%x", message[i]);
	}
}

3、运行结果:

文章来源:https://blog.csdn.net/qq_36075612/article/details/135817340
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。