从字典程序输入(删除标点符号)的问题 [英] issues with input (removing punctuation) from dictionary program

查看:82
本文介绍了从字典程序输入(删除标点符号)的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序接受用户输入(单词/发送)并将其从英语翻译成hmong。我必须使用主变量,但不能发布我的整个代码。


char在[999];

CString in;


基本上是用户cin>>在;然后在= In中,然后使用字典计算。无论如何我可以删除!在我的字典中翻译之前输入的逗号和句点?我一直收到错误代码。


如果我这样做(第一个想法)


if(strcmp(In,"!")) == 0){

in =" love";} //在[i - 1];}


如果你输入!,你得到爱翻译的词(我用爱作为考试)


如果你输入你好! (你得到你好=)然后它的空白,因为它没有从单词中分离出来!...有没有办法比较这种特殊类型字符的最后一个字母,因为你不能像数组那样分析它。通常我会做In [j] ="!"或其他东西,但它不是一个普通的字符/数组,所以它不会让你看一个位置并比较输入。


任何想法?


是否有更简单的方法从翻译中删除标点符号?


帮助我的简单方法:我如何检查/比较单词的最后部分让我们说一个!,如果找到了,用空格替换它?

my program takes users input (words/sentance) and translates it from english to hmong. I have to main variables, but cannot post my entire code.

char In[999];
CString in;

basically the user cin >> In; then later in = In, then computes using the dictionary. is there anyway i can remove ! commas and periods from the input before translating in my dictionary? i keep getting error codes.

if i do this (first idea)

if (strcmp(In, "!") == 0) {
in = "love";} // In[i - 1];}

if you type in !, you get the word love translated (i used love as a test)

if you type in hello! (you get hello = ) then its blank since it doesn''t seperate the word from the !... is there any way to compare the last letter of this special type of character since you cannot analyze it like an array. normally i would do In[j] = "!" or something, but its not a normal character/array so it wont let you look at a position and compare the input.

any ideas?

is there a simpler way in removing punctuation from the translation?

simple way to help me: how can i check/compare the last part of the word for lets say an !, and if it is found, replace it with a space?

推荐答案

我推荐一个正则表达式。他们找到文本并比strtok和strcmp等更容易解析它。


boost regex" Google搜索,我认为他们可以帮助您做您需要的事情。还有其他的正则表达式库,但我不能想到它们,我确定其他贡献者可以添加它们。
I would recommend a regex. They find text and parse it much more easily than strtok and strcmp, et al.

Check out the first two returns from the "boost regex" Google search, I think they can help you do what you need. There are also other regex libraries, but I can''t think of them off the top of my head, I''m sure other contributors can add them.


我不确定我理解你的整个帖子。


但是,告诉你CString有一个方法Replace会替换所有用其他东西找到的字符,或者只是通过替换它们来删除它们可能是有用的。什么都没有。


这听起来有用吗?


如果你想得到更好看并使用更强大的正则表达式,那么我有发现类 CAtlRegExp 是可行的,虽然界面有点奇怪。
I am not sure that I understood your entire post.

However, it may be useful to tell you that CString has a method Replace which will replace all characters found with something else, or just remove them by replacing them with nothing.

Does that sound useful?

If you want to get fancy and use the much more powerful regular expressions, then I have found the class CAtlRegExp to be workable, though the interface is a bit strange.


是的,我认为这超出了我的水平lol。


i也许是因为在[999]我可以找到这个数字! ,然后找!点?使用数字地图,而不是字符
yeah i think this is over my level lol.

i was thining maybe since In[999] i could find the number for ! , then look for the ! point? using the number map, rather then the character


这篇关于从字典程序输入(删除标点符号)的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆