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

Trying to extract words

1
So I'm trying to create a function that will extract a word from a string. I'm trying to do this without creating an array. So far I have this:

string s = "Hello World";
string t;
for (size_t k = 0; k!=s.size(); k++)
{if (isalpha(s[k]))
t+=s[k];
else
???;
}
cout << t << endl;

Basically I'm wondering what to put in the ??? part. Because I want the program to stop taking in characters once it hits a non-letter character.

Or is there any easy method of doing this?
Oct 26 '09 #1
3 3507
whodgson
542 512MB
What is s[k]....an array?
Also what is size_t defined as ....an int?
Which word do you wish to 'extract' ......the first word, the fourth word or some specific word like "?????" ?
Are you intending to print the string, pick the word to extract then extract it? or are you just intending to nominate a word like "thermocouple" and if it happens to be in the string censor it?
Are vectors also banned?..... because you can delete an element from a vector.
Sorry this is so unhelpful
Oct 26 '09 #2
you can put a break statement in place of ????, so that the program will break from the for loop .

string s = "Hello World";
string t;
for (size_t k = 0; k!=s.size(); k++)
{if (isalpha(s[k]))
t+=s[k];
else
break;
}
cout << t << endl;
Oct 26 '09 #3
weaknessforcats
9,208 Expert Mod 8TB
You need to write down your algorithm first. Then code it.

Maybe:

1) remove whitespace
2) move characters to your word until a) you hit whitespace or b) you run out of input.
3) repeat from 1 ofer the next word.
Oct 26 '09 #4

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

Similar topics

44
by: RB | last post by:
How to extract bytes from long, starting from the last byte? For example, I have a long number: 0x12345678 I need to represent it as the following bytes list: 0x78, 0x56, 0x34, 0x12 Thanks in...
3
by: Maya | last post by:
Hello guys, Is there an easy way to extract individual words that form a string and store them in variables like in this example: String "how are you?" My result would be: var1 = "how"
7
by: Sling | last post by:
I code in Rexx on the mainframe which has 2 built-in functions: word(s,i) & words(s). word(s,i) returns the ith word in the s(tring), and words(s) returns the number of words within the s(tring)....
5
by: Jim Carlock | last post by:
I'm looking to use an image of letters and numbers, whereby I need a way to extract each letter and number to create random strings, then combine/conjoin/meld/mesh/merge/unify/unite the images...
0
by: kamal9 | last post by:
#include <stdio.h> #include <string.h> void string2Lines(char line, char tokens){ char *token_ptr, token; char *i=";" " " "," "." "?" "!"; token_ptr = strtok(line, i ); while(token_ptr){...
17
by: Umesh | last post by:
Can anyone do it? ARMY1987- what say?
5
by: 1965 | last post by:
Hi,all. I want to extract all words ( not including punctuations) from a text and convert all individual words into hyperlinks directing a dictionary site. When clicking on any word will go to the...
1
by: Edwin.Madari | last post by:
from each line separate out url and request parts. split the request into key-value pairs, use urllib to unquote key-value pairs......as show below... import urllib line = "GET...
0
by: JohanA | last post by:
I´m using Apose.words to extract diagrams from word 2003 documents. It´s no problem to iterate the embedded MSGraph.Chart.8 objects but I can´t read the data from them. Anyone who knows how to do...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.