Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 1, 2005, 06:06 PM   #1
Beckie
macrumors newbie
 
Join Date: Apr 2005
Question about taking off parts of a word

Hi everyone
I have to getline(cin, string)
Then I have to output the string by separating the words and making them "valid words."

Like for instance I need to change the word To: to the word to
and hat@edu.gov!!! to hat@edu.gov Then I'm supposed to put it into an array.

I think I can do the array part, but I don't know how to output the list of words without the extra characters that don't belong since the list could be an infinite amount of possibilities.

Thanks in advance for the help
Take care,
Beckie
Beckie is offline   0 Reply With Quote
Old May 1, 2005, 11:16 PM   #2
DXoverDY
macrumors 6502a
 
Join Date: Apr 2005
Quote:
Originally Posted by Beckie
Hi everyone
I have to getline(cin, string)
Then I have to output the string by separating the words and making them "valid words."

Like for instance I need to change the word To: to the word to
and hat@edu.gov!!! to hat@edu.gov Then I'm supposed to put it into an array.

I think I can do the array part, but I don't know how to output the list of words without the extra characters that don't belong since the list could be an infinite amount of possibilities.

Thanks in advance for the help
Take care,
Beckie

ok so you need to remove all invalid characters?

ok.. let's give this a little perspective and see if you can figure it out.

there's a bunch of functions in the ctype.h file..

int isdigit( int c) returns true if c is a digit and false otherwise
int isalpha ( int c ) returns true if c is a letter and false otherwise

since i'm not sure exactly what the correct list of "acceptable" characters is i'll give you a very generic way of doing this.

i'd have 2 strings. 1 with the original, and the other with an altered one you'll be building from scratch.

string 1 ... start with string[0] .. cast as an int.. this will give you an integer .. oddly enough it'll give you the ASCII character number for that letter.

uppercase letters are A-Z starting at 65-90 so 65 = A, 90 = Z
lowercase letters are a-z starting at 97-122 so a = 97, z = 122

so... walk through each character of the string and compare your stuff..

for ( int x = 0; x <= strlen(string); x++ ) {

if ( dynamic_cast< int >(string[x]) >= 65 &&
dynamic_cast< int >(string[x]) <= 90 ||
dynamic_cast< int >(string[x]) >= 97 &&
dynamic_cast< int >(string[x]) <= 122 ) {

do what you need to do to copy the character to your other string

}

}

what this does is remove ALL characters that are not A-Z or a-z

look up the ASCII codes for all others you would want as well and throw them in there.

Last edited by DXoverDY; May 1, 2005 at 11:28 PM.
DXoverDY is offline   0 Reply With Quote
Old May 2, 2005, 02:03 AM   #3
Beckie
Thread Starter
macrumors newbie
 
Join Date: Apr 2005
Thank you so much for your help!
Take care,
Beckie
Beckie is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Macbook Pro Internal Parts Question Jman3350 MacBook Pro 5 Jun 9, 2014 08:23 AM
Note Taking Word-Compatible App randomguyishere iPad Apps 2 Feb 13, 2014 05:06 PM
5s flash taking forever when taking pictures cchunk iPhone 9 Oct 19, 2013 04:03 AM
Taking my iPod Classic Running - A question ianwuk iPod 51 Apr 1, 2013 11:32 AM
Taking my iPhone to the Apple store. Question. KidSqueek iPhone 4 Dec 7, 2012 05:36 PM

Forum Jump

All times are GMT -5. The time now is 03:09 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC