473,698 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

issues with input (removing punctuation) from dictionary program

77 New Member
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 3041
sicarie
4,677 Recognized Expert Moderator Specialist
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 New Member
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 New Member
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 Recognized Expert Moderator Specialist
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 New Member
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 New Member
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 Recognized Expert Moderator Specialist
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 New Member
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 New Member
********
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

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

Similar topics

6
16985
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 through a dictionary, looking for things, then remove them.... John
8
5899
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 control. See the code below * Page.aspx: <%@ Page language="c#" Codebehind="Test.aspx.cs" AutoEventWireup="false" Inherits="Webspace.Test" %>
6
6106
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 more minutes. 'REMOVE DUBLICATED VALUE FROM ARRAY +++++++++++++++++ Dim col As New Scripting.Dictionary Dim ii As Integer = 0
17
2709
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 pattern1 print >>orcfilename, line I am pretty sure my code isn't close to what I want. I need to be able
12
2064
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. i'm still in the early stages, and am trying to code something simple and interactive to get the percentages of the portfolio in the five different investment categories. i thought i'd get in with the error handling early so if someone types in...
20
5141
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 to do it word by word. I am confused as to how to do this. Typically, I would think it would make sense to try and input the words into strings, but for this application I need to use character arrays and pointers. So what's the best way to go...
3
3455
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 which has no replace FN? xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx lucason View profile
33
2799
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 = 'hi:cat,bye:dog' Is there a common recipe to accomplish that? I can't come up with any solution...
209
8751
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 stdin. C takes input in 2 ways: 1) as a character, etchar() 2) as a whole line, fgets()
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9023
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7721
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4366
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.