len = strlen(in);
if (in[len-1] == '.')
in = in.TrimRight('.');
you have to declare len, and use cstring for in...
this took me forever lol and its so simple.. i need to set it up for ! points now...
sorry if this is not relevant it took me weeks to figure this out lol and im excited
9 5068
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
errr only problem is if i enter like 30 periods it crashes the program 0.o
Why not just copy the string to a temp and skip the punctuation characters. Then copy the temp back to the original.
??
I mean, you have already done a strlen() so that's the read part of the copy right there.
can you expand on this? i'm a little confused. what do you mean by "skip the punctuation"??? how can i remove it then? thanks!
how can i ignore the chars while making the temp? sounds like a better idea with less if statements
-
char str[] = "H%e*llo.(*&"
-
char temp[100];
-
-
while (str[i] != '\0')
-
{
-
switch (str[i])
-
{
-
case '.':
-
break;
-
case '&':
-
break;
-
case etc... the other puncuation marks
-
break;
-
default:
-
temp[i] = str[i];
-
}
-
++i;
-
}
-
When you leave the loop add a \0 to temp and strcpy(temp, str).
There is also an ispunct() function in stdlib.h that you can use if you want to omit all punctuation instead of specific punctuation.
interesting!!! how could i incorporate that?
well i made a double case statement and it works awesome for now with no memory overflows or crashing:
//punctuation removal
//case statement loops until punctuation is moved
//this prevents error where only one punctuation is fixed and it moves on, this catches quotes and punc."
//default is when input is good/cleaned
len = strlen(in); //sets len as a position for the last letter in
switch (in[0]) //punc removal
{
//case '" (in.Left(1) == '"')
//in = in.TrimLeft('"');
case '!' : in = in.TrimLeft('!');
// break;
case '.' : in = in.TrimLeft('.');
// break;
case '?' : in = in.TrimLeft('?');
// break;
case '"' : in = in.TrimLeft('"');
// break;
case ';' : in = in.TrimLeft(';');
// break;
case ':' : in = in.TrimLeft(':');
// break;
case ',' : in = in.TrimLeft(',');
// break;
default : //break;
len = strlen(in);
switch (in[len -1]){ //punc removal
//case '"' : (in.Left(1) == '"');
//in = in.TrimLeft('"');
case '!' : in = in.TrimRight('!');
// break;
case '.' : in = in.TrimRight('.');
// break;
case '?' : in = in.TrimRight('?');
// break;
case '"' : in = in.TrimRight('"');
// break;
case ';' : in = in.TrimRight(';');
// break;
case ',' : in = in.TrimRight(',');
// break;
case ':' : in = in.TrimRight(':');
// break;
default : //this is like a end loop, once it removes punctuation it moves on
break;
}
}
You really should have a look at the ispunct() function in ctype.h/cctype. It's as
easy as this: -
char* remove_punct(char* dest, char* string) {
-
-
char* t;
-
for (t= dest; *t= *string++; t+= !ispunct(*t));
-
return dest;
-
}
kind regards,
Jos
how can i make that work with a cstring, and in c++? it currently works pretty well/fast but only for like 8 punctuations
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Joseph |
last post by:
I have a textBox that people writes stories in it. They can use
for format.
I have Aspell installed on the server, so people can make correction to
their text. Sometimes, they forget to add a...
|
by: Lachlan Hunt |
last post by:
Hi,
I have recently downloaded and experemented with IBM HPR 3.0, and
Opera 8 with text-to-speech, and have come to realise some fairly
annoying issues regarding punctuation marks.
I've found,...
|
by: MLH |
last post by:
I have a block of text with about 19,000 characters - alphanumeric,
punctuation, hard returns, etc... I would like to count the number of
periods ( Chr$(46) ) appearing in the document. Whats a...
|
by: ZhangZQ |
last post by:
how to remove the apply and help button from propertysheet?
I tried to
this->m_psh.dwFlags &= ~PSH_HASHELP;
this->m_psh.dwFlags |= PSH_NOAPPLYNOW;
this->m_psh.dwFlags |= PSH_NOCONTEXTHELP;
...
|
by: Kun |
last post by:
i have an html/cgi input that takes in values to a mysql database,
however, if i stick in $20 instead of 20, it crashes the program because
of the extra $ sign. I was wondering if anyone has a...
|
by: Tashfeen Bhimdi |
last post by:
I'm trying to remove punctuation from a string with the following
code:
----------------------------
#include <string>
#include <algorithm>
#include <cctype>
..
using namespace std
..
|
by: joe |
last post by:
hello i have a databse program that uses char arrays to output data to
reports. I would like to remove all invalid characters from the array
and replace them with a blank space. I have problems...
|
by: Donos |
last post by:
I have a CString with 100 characters. Now i want to make that to 2
lines.
For example,
CString str = "This is just a test to find out how to break a
cstring";
I want this CString in the...
|
by: Mike Copeland |
last post by:
I have data I need to normalize - it's "name" data. For example, I
have the following: "Watts, J.C." I wish to (1) parse the "first name"
("J.C.") and adjust it to "JC". Essentially, I want to...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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: 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...
| | |