I have a string that includes numbers and letters and I want to be able to seperate the string into parts. An example of the string looks like this FAP834E. I want to seperate it so that the first letter is seperate (F), the second and third are together (AP), the fourth and fifth are together (83), the sixth is seperate (4) and the last is seperate (E).

Please letme know if you can help me

Recommended Answers

All 5 Replies

Please post what you have tried and we can try and help you solve it.

I don't know where to start.

someone told me to use this:

std::string number = "NAB";
for(int i = 0; i < number.size(); i++)
std::cout << number << std::endl;

I have a string that includes numbers and letters and I want to be able to seperate the string into parts. An example of the string looks like this FAP834E. I want to seperate it so that the first letter is seperate (F), the second and third are together (AP), the fourth and fifth are together (83), the sixth is seperate (4) and the last is seperate (E).

Please letme know if you can help me

Look into substr.

Taking advantage of the [] operator is certainly one way to do this. For example, assuming the initial string is always of the same length and always has the same groupings and that you are using the STL string library to create string objects for the initial input as well as the 5 substrings you want to break the input into, then you could use the += operator to build the substrings and the [] operator to access the desired char of the input.

Alternatively you could use STL string methods to extract the substrings. If you want to go this route, then I would refer to your favorite reference book/site.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.