In c++, how can I grab the next few characters from a string? -


my goal grab specific part of large number , concatenate part number, continue. since integers go high, have string of number. not know number be, can't input in myself. can use substr first part, stuck shortly after.

an example

"435509590420924949"

i want take first 5 characters out, convert integer, own calculation them, concatenate them rest of string. take 43550 out, formula 49, add 49 5 in row after original string "95904" new answer "4995904".

this code first part made up,

string temp; int number;  temp = data.substr(0, 5); number = atoi(temp.c_str()); 

this grabs first first characters in strings, converts integers can calculate it, don't know how grab next 5 of long string.

you can length of string, like:

std::size_t startindex = 0; std::size_t blocklength = 5; std::size_t length = data.length(); while(startindex < length) {     std::string temp = data.substr(startindex, blocklength);     // temp     startindex += blocklength;     // todo: skip last "block" if < blocklength,     // need modify bit case. } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -