求C语言去掉句号符的方法

weinikuaile 2013-05-17 10:16:47
现有一个字符串数组char a[] = {海口.。.。},我想去掉其中的中文字符(句号) 。,如何可以去掉咧?
...全文
556 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yhgfriend 2014-09-19
  • 打赏
  • 举报
回复
引用 7 楼 weinikuaile 的回复:
哦, [quote=引用 6 楼 shen_wei 的回复:] 转换成CString类。。这个还是比较快的
呵呵,谢谢,我定义的是结构体 使用了好些的char[]型数组,暂时就不改了,我测试使用看看。[/quote] 用CString,处理完再将CString 复制到CHAR[]数组就行了,又快又简单 例: char buf[100]="1。23。456。789。"; CString str;str.Format("%s",buf); str.Replace("。",NULL); //删除句号 sprintf_s(buf,sizeof(buf),"%s",str); //反处理后的数据拷贝回数组 处理完成了
LubinLew 2014-09-19
  • 打赏
  • 举报
回复
strtok不支持unicode, 虽然在大部分情况下好用,但是遇到和句号编码第一个字节相同的字符串就完蛋了, 比如"第一个", "非常" 等.
引用 9 楼 kangyp 的回复:
void func2(char **buf,const char* split) { int len=strlen(*buf)+1; char *buf2=new char[len]; memset(buf2,0,len); char *p=strtok(*buf,split); while(p) { strcat(buf2,p); p=strtok(NULL,split); } strcpy(*buf,buf2); delete buf2; } //例子 char buf[100]="1。23。456。789。"; char* p=buf; func2(&p,"。"); printf("%s\n",buf);
Kang哥 2013-05-25
  • 打赏
  • 举报
回复
void func2(char **buf,const char* split) { int len=strlen(*buf)+1; char *buf2=new char[len]; memset(buf2,0,len); char *p=strtok(*buf,split); while(p) { strcat(buf2,p); p=strtok(NULL,split); } strcpy(*buf,buf2); delete buf2; } //例子 char buf[100]="1。23。456。789。"; char* p=buf; func2(&p,"。"); printf("%s\n",buf);
weinikuaile 2013-05-20
  • 打赏
  • 举报
回复
哦,
引用 6 楼 shen_wei 的回复:
转换成CString类。。这个还是比较快的
呵呵,谢谢,我定义的是结构体 使用了好些的char[]型数组,暂时就不改了,我测试使用看看。
shen_wei 2013-05-20
  • 打赏
  • 举报
回复
转换成CString类。。这个还是比较快的
weinikuaile 2013-05-20
  • 打赏
  • 举报
回复
引用 3 楼 hankcs 的回复:
好久不写C了,见笑了
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
	char a[] = "海口.。.。";
	cout << a << endl;
	char tem[3];
	char szFinal[1024];
	memset(tem, 0, sizeof(tem));
	memset(szFinal, 0, sizeof(szFinal));
	//cout << sizeof(szFinal) << endl;
	/*cout << tem << endl;*/
	int nLength = strlen(a);
	int j = 0;
	for (int i = 0; i < nLength - 1; i++)
	{
		memcpy(tem, &a[i], 2);
		//cout << tem << endl;
		if (strcmp(tem, "。"))
		{
			memcpy(&szFinal[j], tem, sizeof(tem));
			j++;
		}
	}
	cout << szFinal << endl;
	system("pause");
	return 0;
}
------------------------------------------------------AutoCSDN签名档------------------------------------------------------
码农场——码农播种代码、放牧思想的农场!
呵呵,谢谢,上面的方式有点儿小问题,目前已经解决了。我在您的这两个函数memcpy(tem, &a[i], 2) (strcmp(tem, "。"))基础上改进如下:
RemoveBlankperiod(char c[])
{
	char *p =c,*q;
	char tem[3];
	memset(tem, 0, sizeof(tem));
	int nLength = strlen(c);
	static int nLen = nLength;
	int j = 0;
	for (int i = 0; i < nLength - 1; i++)
	{
		memcpy(tem, &c[i], 2);
		if (strcmp(tem, "。"))
		{
			p++;
		}
		else
		{ 
			q = p;
			nLen -= 2;
			j = 0;
			while (j < nLen)
			{
				*q = *(q+2);
				q++;
				j++;
			}
			p++;
			*q ='\0';		
		}
	}
	return 0;
}
threenewbee 2013-05-18
  • 打赏
  • 举报
回复
转换成CString,然后Replace好了。
hankcs 2013-05-18
  • 打赏
  • 举报
回复
好久不写C了,见笑了
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
	char a[] = "海口.。.。";
	cout << a << endl;
	char tem[3];
	char szFinal[1024];
	memset(tem, 0, sizeof(tem));
	memset(szFinal, 0, sizeof(szFinal));
	//cout << sizeof(szFinal) << endl;
	/*cout << tem << endl;*/
	int nLength = strlen(a);
	int j = 0;
	for (int i = 0; i < nLength - 1; i++)
	{
		memcpy(tem, &a[i], 2);
		//cout << tem << endl;
		if (strcmp(tem, "。"))
		{
			memcpy(&szFinal[j], tem, sizeof(tem));
			j++;
		}
	}
	cout << szFinal << endl;
	system("pause");
	return 0;
}
------------------------------------------------------AutoCSDN签名档------------------------------------------------------
码农场——码农播种代码、放牧思想的农场!
西山小月 2013-05-18
  • 打赏
  • 举报
回复
读入内存,查找,匹配,删除,存储
qukuai_yin 2013-05-18
  • 打赏
  • 举报
回复
找到内存的位置,如oxff7c; char *p = oxff7c; 去掉其内存位置。

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧