473,326 Members | 2,255 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,326 software developers and data experts.

Removing Spaces and Punctuations From a Line

I was wondering if someone can show me how to remove spacing and punctuations from a line of input using character functions(such as is punct., is space) I also want to use a for loop to do it. I just don't know where to start on this. I think I should use if statements stating if(i is space) then remove it but im not sure how too do that.

Thanks,
Nov 19 '06 #1
6 2189
sivadhas2006
142 100+
Hi,

Can you post your program whatever you have tried to do that?

Regards,
M.Sivadhas.
Nov 20 '06 #2
yeah no problem.
for(i=0; i<str.size(); ++i)
{
if(i is punct.)
str.erase(i,1)
if(i is space)
str.erase(i,1)
}
Nov 20 '06 #3
Banfa
9,065 Expert Mod 8TB
That is not that bad a start, however you only want to increment i if you haven't erased a character
Nov 20 '06 #4
I think I am going to create a temporary string:

string CleanString (string old, int& numspaces, int& numpunct)
{
string newold;
for(int i=0; i<old.size(); ++i)
{

if(!isspace(old[i]) || !ispunct(old[i]))
newold = newold+old[i];
}
Nov 20 '06 #5
Banfa
9,065 Expert Mod 8TB
I think I am going to create a temporary string:
Not a bad plan but

1. initialise newold to ""

2. newold = newold+old[i]; would be better written

newold += old[i];

as it doesn't envolve the creation of a temporary string for the expression.
Nov 20 '06 #6
[quote=Banfa]Not a bad plan but

1. initialise newold to ""

2. newold = newold+old[i]; would be better written

newold += old[i];

as it doesn't envolve the creation of a temporary string for the expression.[/QUOTE

Thanks for the help
Nov 20 '06 #7

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

Similar topics

1
by: Andy Visniewski | last post by:
I have three columns, RecordID, FirstName, and LastName, but somehow through some program glitch, there is sometimes a trailing space in the firstname and lastname columns, for example, a persons...
11
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white...
12
by: Magix | last post by:
Hi, Everytime I received a fix-length of string, let say 15 (the unused portion will filled with Spaces before receive), I want to remove the Spaces from END until I encounter a non-space char....
3
by: lino | last post by:
Hello, I have the following string: const char plaintext = "Fourscore and seven years ago our \ fathers brought forth upon this continent \ a new nation, conceived in liberty, and dedicated...
2
by: vijayk | last post by:
Hi All, I want to remove all the punctuations in an address column if any: Select translate(ADDR,' ',':;.,!?-') from Table; I am able to remove all except for single quote ('). Can...
9
by: David Pratt | last post by:
Hi. I'm trying to clean files for packaging on mac using os.path.walk and want to clean the .DS_Store files that are hidden from view but could end up in code that I produce. # Clean mac...
2
by: beatTheDevil | last post by:
Hey guys, As the title says I'm trying to make a regular expression (regex/regexp) for use in removing the comments from code. In this case, this particular regex is meant to match /* ... */...
2
code green
by: code green | last post by:
I am trying to write a simple function that will take a string containing an address line or business name and return it nicely formatted. By this I mean extra spaces removed and words capitalised....
8
by: drjay1627 | last post by:
hello, This is my 1st post here! *welcome drjay* Thanks! I look answering questions and getting answers to other! Now that we got that out of the way. I'm trying to read in a string and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.