By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,671 Members | 1,637 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,671 IT Pros & Developers. It's quick & easy.

help with removing punctuation and uppercase letters from a string...

P: 77
i have a great program now with the help of a member from this site, but i need a little customization to meet the needs of non-english speakers... who might accidendtly type punctuation which would give a false negative dictionary response... so if the user types in:

i need uppercase to become lowercase too

what i would like is to remove commas, periods, exclamation points and question marks and apostrophes from the strings before it searches the dictionary but it needs to be quick code so it doesn't bog down the program.

i've read several ideas but i could not get them to work.. my inputs tring is called "In" and i already have an integer used called i, so i'd need to keep that in mind. any suggestions? once the code is cleaned up, it would be sent too the rest of the program for computing the translations. first i need to remove punctuation... if possible to switch capital letters with lowercase. another idea would be to replace punctuation with spaces if it is to complicated to program, and to recode uppercase to lowercase. please post any ideas if possible thank you! i am distributing this dicitonary free to refugee students so i'll make sure to include your name in the code.

examples of issues:
love = hlub

great! (translation success)

but if they type

Love

they get

Love =

and if they type

love!

they get

love =
Jun 23 '07 #1
Share this Question
Share on Google+
4 Replies


P: 77
should this be done as a string, or a string case by case, then recreated as a string? 0.o
Jun 24 '07 #2

Expert 10K+
P: 11,448
should this be done as a string, or a string case by case, then recreated as a string? 0.o
Have a look at the <ctype.h> file: it defines the macros your need: isupper(),
tolower(), isalpha(), isspace() etc. If a current character isn't an alpha, nor a
whitespace remove it from your string, otherwise convert to lowercase if needed
and check the next character in the string. A single loop can do the job.

kind regards,

Jos
Jun 24 '07 #3

P: 77
thanks i'll check it out!

which to specifically remove punctuation and switch uppercase to lowercase?

i know tlower is one, and then?

will talpha accidently remove my spaces? i don't want that either


i tried some other fucntions and it actually broke my program and wouldnt reopen until i manually removed those lines lol... 0.o

i basically have an input string that goes a whole great amount of complex programming (dictionary) but i really need some help with removing the punctuation/uppercase letters converted to lowercase...

i need to declare the function, but then after user...

cin >> In;

how do i compute In, using the tlower and punctuation functions?

maybe my program is a little to complex for me that i'm not declaring the functions properly. i'll ask the creator for some assistance
Jun 24 '07 #4

weaknessforcats
Expert Mod 5K+
P: 9,197
Also have a look in the C/C++ Articles forum for the State Design Pattern. There is example code that does this sort of thing for you. I expect you could copy the example and be running in an hour.
Jun 24 '07 #5

Post your reply

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