#include<iostream>
#include<string>
#include<stdlib.h>
usingnamespace std;
int main()
{
std::string str="EmployeeId=1234;EmployeeName=Som;EmployeeSalary=123456;";
//Delimiter is semicolon
std::string reqString;
int iPos = str.find(";");
/*
npos is a static member constant value with the greatest possible value for an element of type size_t.
This value, when used as the value for a count parameter n in string's member functions, roughly indicates "as many as possible".
hen used in some pos parameters that allow for out-of-range values, npos indicates the end of the string.
As a return value it is usually used to indicate failure.
*/
while(iPos != string::npos)
{
reqString = str.substr(0/*intial position*/,iPos);
cout<<reqString.c_str()<<endl;
//if you dont want to erase keep a copy of the string
str.erase(0,iPos+1);
iPos = str.find(";");
}
return 0;
}
this is the input string ad i want to split the string with "= Payments::"
The output will be like it will splits three string arrays as
splitted_array[1]="Source:Registration \n Table:Calls \n Options: \n Calls::date = ";
splitted_array[2]="PayDate \n \n Source:Registration \n Table:Employee \n Options: \n Employee::Id ";
splitted_array[3]="EmpId";
as i am splitting the string with the string "= Payments::";