本文主要是介绍抽离字符串中字符和数字,并不改变原来的字母数字之间顺序再组合,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
// test.cpp : 定义控制台应用程序的入口点。
//#define _CRT_SECURE_NO_WARNINGS#include "stdafx.h"// test.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#include <stdlib.h>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;char * apple1(char * str){char * Body = (char *)malloc(strlen(str) + 1);char * tmp = (char *)malloc(strlen(str) + 1);char * tmpnum = (char *)malloc(strlen(str) + 1);char * start = tmp;char * numstart = tmpnum;while (*str != '\0') {if ((*str >= 'A'&&*str <= 'Z') || (*str >= 'a'&&*str <= 'z')) {*tmp = *str;tmp++;}else if (*str >= '0'&&*str <= '9'){*tmpnum = *str;tmpnum++;}str++;}*tmp = '\0';*tmpnum = '\0';cout << start << endl;cout << numstart << endl;strcpy_s(Body, strlen(Body), start);strcat(Body, numstart);cout << Body << endl;free(start);free(numstart);return Body;
}int _tmain(int argc, _TCHAR* argv[])
{char * str = "1919china";char * dst1 = (char *)apple1(str);return 0;
}
这篇关于抽离字符串中字符和数字,并不改变原来的字母数字之间顺序再组合的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!