473,379 Members | 1,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

issues with input (removing punctuation) from dictionary program

77
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?
Jul 26 '07 #1
13 3004
sicarie
4,677 Expert Mod 4TB
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.
Jul 26 '07 #2
ravenspoint
111 100+
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.
Jul 26 '07 #3
jerger
77
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
Jul 26 '07 #4
sicarie
4,677 Expert Mod 4TB
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
Well, if you are doing it that way, I'd recommend looking at the cstring.h reference. I think those will help.
Jul 26 '07 #5
ravenspoint
111 100+
Don't give up on Replace. It isn't hard to use.
Expand|Select|Wrap|Line Numbers
  1.     CString in = "love!";
  2.     CString in2 = in;
  3.     in2.Replace( "!", "" );
  4.     cout << in << in2 << endl;
  5.  
Jul 26 '07 #6
jerger
77
hmm... but cstring doesn't = "a word"... it ='s the input from the cin line... before its sent through the dictionary..

anyway to find a ! in that word, then remove the ! if found?

what are the types of ways for removing the last letter in an array, i remeber something like "word.size()" and check if its there, then remove it... but i bet there is a better way... err im writing the programmer too
Jul 26 '07 #7
sicarie
4,677 Expert Mod 4TB
hmm... but cstring doesn't = "a word"... it ='s the input from the cin line... before its sent through the dictionary..

anyway to find a ! in that word, then remove the ! if found?

what are the types of ways for removing the last letter in an array, i remeber something like "word.size()" and check if its there, then remove it... but i bet there is a better way... err im writing the programmer too
I really would use a string to hold what is read in, then strtok() to find the delimiter, and substr() to pull it out.

That really seems to me to be the asiest way to do what you are saying, but I might be missing something. Can you give a little higher-level idea of what you want to do?
Jul 26 '07 #8
jerger
77
i have to talk to the programmer about posting more information since he doesn't want his code taken.. but

i should study c++ more lol

we have char's, which i don't understand how they are stored since i always though char was one spot, not multiple... so it must be a special string as well.
Jul 26 '07 #9
jerger
77
********
i had an idea this morning, since the char[999] variable is hard to manipulate... maybe when in = In, i could then manipulate in before in is sent to the function.

what is the part of code to check the last part of a char array (last resort string too), char (is it possible) and in addition string.

what i need cleared up is like using word.size() or something similiar in an if statement that i could then check if the last character of the input to check would match a !, if it does, delete it? or change it to a space.

i was thinking i might need t ouse character maps numbers instead of ! for example
Jul 27 '07 #10
jerger
77
in = In;

//in.ReleaseBuffer(); // Things are now OK
punc = in.GetLength(); // This is guaranteed to be correct
while (in[punc] = '!'){
//in.TrimRight();
in = "love";
}



"..\..\..\..\..\..\..\Translator.cpp(127) : error C2106: '=' : left operand must be l-value"
Jul 27 '07 #11
jerger
77
i think i have to do something like this with the cstring, but not sure what to do yet to make it not crash

len = strlen(word); //this line made it stop crashing but now has no effect


//original post
if (in[len-1] == '.' || in[len-1] == '?')
in[len-1];= '\0';

//only works if i use == instead of =''\0" , if i do that i get error like cant use l-value


..\..\..\..\..\..\..\Translator.cpp(147) : error C2106: '=' : left operand must be l-value
Build log was saved at "file://c:\Documents and Setting

in is a cstring, In is char 999

in = In; //important

//
//if (in[strlen(szInput))] == '!')
//in = "love";
len = strlen(in);
if (in[len-1] == '.')
in[len-1] = '\0';
Jul 31 '07 #12
jerger
77
woot 4am i figured it out!

len = strlen(in);
if (in[len-1] == '.')
in = in.TrimRight('.');
Jul 31 '07 #13
jerger
77
punk is int, len is int, in is cstring

//punctuation removal
//while loop checks several times to catch all punctuation

while (punk < 10){
len = strlen(in);
if (in.Left(1) == '"')
in = in.TrimLeft('"');

if (in[len-1] == '.')
in = in.TrimRight('.');

if (in[len-1] == '"')
in = in.TrimRight('"');

if (in[len-1] == '!')
in = in.TrimRight('!');

if (in[len-1] == ',')
in = in.TrimRight(',');

if (in[len-1] == '?')
in = in.TrimRight('?');

if (in[len-1] == ':')
in = in.TrimRight(':');

if (in[len-1] == ';')
in = in.TrimRight(';');

punk++;
}
punk = 0;
//end of punctuation check
Jul 31 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: JohnK | last post by:
ok, ya got me here. I'm trying to removing items from a dictionary inside a loop. Obviously using enumeration does not work as that assumes the dictionary stays unchanged. So how so I iterate...
8
by: David Cameron | last post by:
I noticed that using an HTMLInputRadioButton and specifying a value to be an empty string (""), this is overridden by ASP.Net which set the value of the control to be the same as the ID of the...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
17
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not...
12
by: sam | last post by:
hi all, i'm starting to put together a program to simulate the performance of an investment portfolio in a monte carlo manner doing x thousand iterations and extracting data from the results. ...
20
by: dmurray14 | last post by:
Hey guys, I'm a C++ newbie here - I've messed with VB, but I mostly stick to web languages, so I find C++ to be very confusing at times. Basically, I am trying to import a text file, but I want...
3
by: MLH | last post by:
Back in mid-2003, lucason posted a question about removing punctuation chars from a string. Suggested code was posted using Replace function. Could the FN below be easily modified for use with A97...
33
by: cesco | last post by:
Hi, say I have a string like the following: s1 = 'hi_cat_bye_dog' and I want to replace the even '_' with ':' and the odd '_' with ',' so that I get a new string like the following: s2 =...
209
by: arnuld | last post by:
I searched the c.l.c archives provided by Google as Google Groups with "word input" as the key words and did not come up with anything good. C++ has std::string for taking a word as input from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.