Find data in string, send to new string.

Here's the program so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <string>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main()
{

    int i;
    string found;
    string str;
    string detailnumber;
    string detailsearch;
    string killarray [150];
    string debug;
    //GET SYSTEM ID FOR ZKILLBOARD
    cout << "Enter the Zkillboard.com system ID" << endl;
    string boardloc;
    cin >> boardloc;
    string a = "http://zkillboard.com/system/";
    string b = "/kills/";
    string actloc = a+boardloc+b;
    string wget = "wget "+actloc;
    //GET FILES FOR THAT SYSTEM
    //*system(wget); Well this is broken too. *//
    fstream master;
    master.open ("index.html");


    while (master.good()) //Where do we go now, sweet child, where do we go now , owah ah ah ah ah ah aaah
    {
        getline(master,debug);
        cout << debug << endl; //from here all the shit happens
    }
    return 0;
}


okay so, when we get line into debug (will later be something else) we need to search for "detail/*" and send whatever comes between detail/ and the next "/" to another string so we can use it later.

also I'm using wget to avoid having to touch an in code version, just calling system wget is way easier (even if it doesn't work at the minute, although if you want to let me know where I'm fucking up with that I can fix that too)

I've attempted to get boost to play nice with codeblocks but I'm being shit and it's just not working (Read tutorials, watched walk throughs and just wound up with crazy ass errors that nobody else seemed to get)
Last edited on
Hi there,

I believe std::string.find ( http://cplusplus.com/reference/string/string/find/ ) is what you're looking for:

1
2
3
4
size_t start = debug.find("detail/", 0);  //get start of substring position
size_t end = debug.find("/", start+8);  // "detail/" is 7 characters, so look for first / after that

std::string detail_txt(debug, start, end-start); //string constructor from substring 


It may be worth checking if start or end == std::string::npos, to make sure both are actually found.
Any more information can be found in the <string> reference:

http://cplusplus.com/reference/string/string/

Hope that helps.

All the best,
NwN
having some troubles with

std::string detail_txt(debug, start, end-start); //string constructor from substring


I'll keep playing and see if I can get something to work.

Thanks.
You could also do:

std::string detail_txt = debug.substr(start, end-start);

That should do the same.

All the best,
NwN
Topic archived. No new replies allowed.