c++stringhwid

C++ - How can i split up 3 lines safed in string called "result" and create a oneline "synonym" for all 3 strings. - C++


So, Hello Guys.

I have a function, which reads the Diskdrive Serialnumber. I get a output like this:

SerialNumber A6PZD6FA 1938B00A49382 0000000000000 (thats not my serialnumber, just the format)

So now, i want to split the 3 numbers, or strings, however i call it you know what i mean, and save it in in three independent strings.

string a = {A6PZD6FA this value} string b = {1938B00A49382 this value} string c = {0000000000000 this value}

After that, i want to create a oneline "synonym" for all 3 strings. So i mean, string synonym = 04930498SV893948AJVVVV34 something like this.


Solution

  • If you have the original text in a string variable, you can use a std::istringstream to parse it into constituent parts:

    std::string s = "SerialNumber A6PZ etc etc...";
    std::istringstream iss{s};
    std::string ignore, a, b, c;
    if (iss >> ignore >> a >> b >> c) {
        std::string synonym = a + b + c;
        ...do whatever with synonym...
    } else
        std::cerr << "your string didn't contain four whitespace separated substrings\n";