In: Computer Science
How to tokenize a string date of
format dd/mm/yyyy into
day,month and year without using built in function of strok() or
any other built in function in C++ (without classes).
Kindly help Please .
#include <iostream> using namespace std; int intValue(string s) { int val = 0; for(int i=0; i<s.length(); i++) { val = val * 10 + (s[i] - '0'); } return val; } int main() { string s = "21/02/2018"; // We will be creating the substrings of the string // using / character.. // Substring function takes the start index and the // length of the string to be taken int m, y, d; d = intValue(s.substr(0, 2)); m = intValue(s.substr(3, 2)); y = intValue(s.substr(6, 4)); cout << "Day: " << d << endl; cout << "Month: " << m << endl; cout << "Year: " << y << endl; }
************************************************** Answered without any built in function for tokenization.. Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.