0

From this wikipedia article(http://en.wikipedia.org/wiki/Magnetic_stripe_card#cite_note-14), I understand the basic data format for driver's license. It starts with the location data which looks like this: %CODENVER^

I am wondering what if the city consists of two or more words like New York City?

What does the data output look like, and is it a white-space character that separates the words, or it's something else?

How do I write a c++ statement to return each word in the city name in different strings?

Thomas Matthews
  • 52,985
  • 12
  • 85
  • 144
Glenna
  • 135
  • 1
  • 5
  • 3
    I guess you would have to write C++ code **that parses** a string, or you can write **a regular** expression. If you haven't used the internet for searching, now is a good time to learn. Do you know what keywords to use? – Thomas Matthews May 31 '15 at 22:34
  • The page you linked mentions a field separator character following the city name; presumably read up to that or the maximum field length and treat white-space chars like any other. – Jonathan Potter Jun 01 '15 at 04:04

1 Answers1

0

It will depend on the delimiter. States use different formats for their data. Mag stripes will have one delimiter to split the data into different sections, then another delimiter to split the sections into individual parts.

For an example, let's say that the data you want to parse is:

New^York^City

Use something like this to split it out:

int main()
{
    std::string s = "New^York^City";
    std::string delim = "^";

    auto start = 0U;
    auto end = s.find(delim);
    while (end != std::string::npos)
    {
        std::cout << s.substr(start, end - start) << std::endl;
        start = end + delim.length();
        end = s.find(delim, start);
    }

    std::cout << s.substr(start, end);
}

Then your output should be:

New
York
City

Search more for C++ string parsing. I used the split function from here: Parse (split) a string in C++ using string delimiter (standard C++)

Community
  • 1
  • 1
Frackinfrell
  • 192
  • 1
  • 11