Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "MyString.h"
- bool operator == (const MyString& S1, const MyString& S2)
- {
- if (S1.length == S2.length)
- {
- short counter1 = S1.length;
- int mis = 0;
- int i = 0;
- while (i != counter1)
- {
- if (S1.str[i] != S2.str[i]) { mis++; }
- i++;
- }
- if (mis != 0) { return false; }
- else { return true; }
- }
- else { return false; }
- }
- ostream& operator <<(ostream& OS, const MyString& S)
- {
- OS << S.str;
- return OS;
- }
- istream& operator >>(istream& IS, MyString& S)
- {
- char* input = new char[100];
- IS.getline(input, 100);
- int i = 0;
- while (input[i] != '\0')
- {
- i++;
- }
- S.length = i + 1;
- delete[]S.str;
- S.str = new char[(i + 1)];
- for (int j = 0; j < (i); j++)
- {
- S.str[j] = input[j];
- }
- S.str[i] = '\0';
- delete[]input;
- return IS;
- }
- bool MyString::isEmpty()
- {
- if (str[0] == NULL && length == 1)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- int find(const MyString& S1,const MyString& S2)
- {
- int index = 0;
- int strsize1 = S1.length;
- int strsize2 = S2.length;
- int counter = 0;
- int checker = 0;
- for (int i = 0;checker!=strsize2 || i<strsize1;i++)
- {
- if (S2.str[checker] == S1.str[i])
- {
- checker++;
- index = i;
- }
- if (checker > 0 && S2.str[checker] == S1.str[i] && checker != (i - 1))
- {
- return -1;
- }
- }
- index =index-checker+1;
- if (checker == strsize2)
- {
- return index;
- }
- else
- {
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement