Theme
Primary Color
Lesson 14

Parse String

محتوى الدرس

#include <iostream>
using namespace std;

/*
  Parse String From Query String
  name=Osama&age=43&country=Egypt

  name: Osama
  age: 40
  country: Egypt
*/

string parse_string(string st)
{
  string result;
  /*
    name    : Osama
    age     : 43
    country : Egypt
  */

  for (int i = 0; i < st.length(); i++)
  {
    if (st[i] == '=')
    {
      result += ": ";
      continue;
    }
    if (st[i] == '&')
    {
      result += "\n";
      continue;
    }
    result += st[i];
  }

  return result;
}

int main()
{
  cout << parse_string("name=Osama&age=43&country=Egypt") << endl;
  return 0;
}