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?
13 3006
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.
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.
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
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.
Don't give up on Replace. It isn't hard to use. -
CString in = "love!";
-
CString in2 = in;
-
in2.Replace( "!", "" );
-
cout << in << in2 << endl;
-
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
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?
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.
********
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
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"
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';
woot 4am i figured it out!
len = strlen(in);
if (in[len-1] == '.')
in = in.TrimRight('.');
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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 =...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |