Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gmmastros on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function dividing chunks of characters, strings

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
0
0
I need to find a function that divides a string into parts based on what the user defines as the part to divide it by. Confusing, wait, example: 'cyprus.was.here' the user wants to divide this string into parts based on the '.', so there would be 3 parts: 'cyprus', 'was', and 'here'. or if i wanted to break it up by 'y', it would be: 'c' and 'prus.was.here'.
somewhat like fnsplit, but with a designated string, and a designated segimant divider, as opposed to a file name and '\\'. I'm not exactly sure where to start here, and I don't have ANY time to even attempt it, so I was desperately hoping someone out here might know. Cyprus
 
Look carefully at the getline function. This is part of the STL and is in the string header (this is the C++ string and not BCB String). One of the functions of getline is to copy characters from one string into another string until a delimiter is found or the end of the input string is found. The following code is from memory so it may not compile as it.
Code:
#include <string.h>
#include <iostream.h>

using std namespace;

int main()
{
    string TheString = &quot;Jim.was.here&quot;;
    string Name, Verb, Ad;

    getline(TheString,Name,'.'); // To first period
    getline(TheString,Verb,'.'); // From first period to second
    getline(TheString,Ad,'/n'); // From second period to end of line

    cout << Name << &quot; &quot; << Verb << &quot; &quot; << Ad << endl;
    return 0;
}

You may have to play with this as I'm doing this from memory. James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
hey! thats it! i suspected that there was a function like that, but i didnt know it and didn't look. thanks! Cyprus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top