Theme
Primary Color
Lesson 12

Get Sub String

محتوى الدرس

#include <iostream>
using namespace std;

// Get Sub String

string substring(string st, int start, int end, bool inc_end, bool countspace)
{
  string result;
  for (int i = start; inc_end ? i <= end : i < end; i++)
  {
    if (!countspace && st[i] == ' ')
    {
      end++;
    }
    result += st[i];
  }
  return result;
}

int main()
{
  cout << substring("Elzero Web School", 0, 8, true, true) << endl;
  return 0;
}