This commit is contained in:
RafayAhmad7548 2024-06-16 18:53:25 +05:00
parent 37776af5db
commit ab03d5f10c
4045 changed files with 286212 additions and 3 deletions

View file

@ -0,0 +1,222 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
string input;
cout<<"Enter a string:\n";
getline(cin, input);
String str((char*)input.c_str());
str.trim();
str.print();
// test all functuins
cout<<"Length: "<<str.strLength()<<endl;
cout<<"Empty: "<<str.empty()<<endl;
char c;
cout<<"Enter a character to find in the string:\n";
cin>>c;
cout<<"Character found at index: "<<str.charAt(c)<<endl;
char substr[100];
int startIndex, endIndex;
cout<<"Enter a substring to find in the string:\n";
cin>>substr;
cout<<"Enter start index:\n";
cin>>startIndex;
cout<<"Enter end index:\n";
cin>>endIndex;
cout<<"Substring: ";
str.substring(substr, startIndex, endIndex).print();
return 0;
}

View file

@ -0,0 +1,153 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
this->data = this->substring(start, end);
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,163 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
this->data = this->substring(start, end);
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,149 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
this->data = this->substring(start, end);
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,185 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,147 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,185 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,183 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}else{
newStr[j++] = str1.getData()[i];
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,184 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
// remove all occureces of substr in this
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<str1.strLength();i++){
if(str1.substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[str1.strLength()-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<str1.strLength();i++){
if(str1.substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}else{
newStr[j++] = str1.getData()[i];
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,183 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,165 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
this->toLowerCase();
for(int i=0;str[i]!='\0' && i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
this->data = this->substring(start, end);
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,183 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(str1.substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}else{
newStr[j++] = str1.getData()[i];
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,230 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
// test all functions
String str("Hello World");
cout<<"String: ";
str.print();
cout<<"Length: "<<str.strLength()<<endl;
cout<<"Empty: "<<str.empty()<<endl;
cout<<"Char at 'W': "<<str.charAt('W')<<endl;
cout<<"Char at 'w': "<<str.charAt('w')<<endl;
cout<<"Data: "<<str.getData()<<endl;
cout<<"Equals 'Hello World': "<<str.equals("Hello World")<<endl;
cout<<"Equals 'hello world': "<<str.equals("hello world")<<endl;
cout<<"Equals Ignore Case 'hello world': "<<str.equalsIgnoreCase("hello world")<<endl;
cout<<"Equals Ignore Case 'Hello World': "<<str.equalsIgnoreCase("Hello World")<<endl;
cout<<"Substring(6, 11): ";
str.substring(6, 11).print();
// cout<<"Substring 'World' (2): ";
// str.substring("World", 2).print();
// cout<<"Substring 'World' (2, 7): ";
// str.substring("World", 2, 7).print();
cout<<"Starts with 'Hello': "<<str.startsWith("Hello")<<endl;
cout<<"Ends with 'World': "<<str.endsWith("World")<<endl;
cout<<"Ends with 'world': "<<str.endsWith("world")<<endl;
cout<<"Concatenate '!!!': ";
str.concatenate("!!!");
str.print();
cout<<"Insert '!!!' at 5: ";
str.insert(5, "!!!");
str.print();
cout<<"Remove '!!!': ";
str.remove("!!!");
str.print();
cout<<"Trim: ";
str.trim();
str.print();
cout<<"To Upper Case: ";
str.toUpperCase();
str.print();
cout<<"To Lower Case: ";
str.toLowerCase();
str.print();
return 0;
}

View file

@ -0,0 +1,221 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
string input;
cout<<"Enter a string:\n";
getline(cin, input);
String str((char*)input.c_str());
str.trim();
str.print();
cout<<"Length: "<<str.strLength()<<endl;
cout<<"Empty: "<<str.empty()<<endl;
char c;
cout<<"Enter a character to find in the string:\n";
cin>>c;
cout<<"Character found at index: "<<str.charAt(c)<<endl;
char substr[100];
int startIndex, endIndex;
cout<<"Enter a substring to find in the string:\n";
cin>>substr;
cout<<"Enter start index:\n";
cin>>startIndex;
cout<<"Enter end index:\n";
cin>>endIndex;
cout<<"Substring: ";
str.substring(substr, startIndex, endIndex);
return 0;
}

View file

@ -0,0 +1,149 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,184 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
// remove all occureces of substr in this
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<str1.strLength();i++){
if(str1.substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[str1.strLength()-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<str1.strLength();i++){
if(str1.substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}else{
newStr[j++] = str1.getData()[i];
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,149 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
for(int i=0;i<this->size;i++){
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,232 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
// test all functions
String str("Hello World");
cout<<"String: ";
str.print();
cout<<"Length: "<<str.strLength()<<endl;
cout<<"Empty: "<<str.empty()<<endl;
cout<<"Char at 'W': "<<str.charAt('W')<<endl;
cout<<"Char at 'w': "<<str.charAt('w')<<endl;
cout<<"Data: "<<str.getData()<<endl;
cout<<"Equals 'Hello World': "<<str.equals("Hello World")<<endl;
cout<<"Equals 'hello world': "<<str.equals("hello world")<<endl;
cout<<"Equals Ignore Case 'hello world': "<<str.equalsIgnoreCase("hello world")<<endl;
cout<<"Equals Ignore Case 'Hello World': "<<str.equalsIgnoreCase("Hello World")<<endl;
cout<<"Substring(6, 11): ";
str.substring(6, 11).print();
cout<<"Substring 'World': ";
str.substring("World").print();
cout<<"Substring 'World' (2): ";
str.substring("World", 2).print();
cout<<"Substring 'World' (2, 7): ";
str.substring("World", 2, 7).print();
cout<<"Starts with 'Hello': "<<str.startsWith("Hello")<<endl;
cout<<"Ends with 'World': "<<str.endsWith("World")<<endl;
cout<<"Ends with 'world': "<<str.endsWith("world")<<endl;
cout<<"Concatenate '!!!': ";
str.concatenate("!!!");
str.print();
cout<<"Insert '!!!' at 5: ";
str.insert(5, "!!!");
str.print();
cout<<"Remove '!!!': ";
str.remove("!!!");
str.print();
cout<<"Trim: ";
str.trim();
str.print();
cout<<"To Upper Case: ";
str.toUpperCase();
str.print();
cout<<"To Lower Case: ";
str.toLowerCase();
str.print();
return 0;
}

View file

@ -0,0 +1,183 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<str1.strLength();i++){
if(str1.substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[str1.strLength()-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<str1.strLength();i++){
if(str1.substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}else{
newStr[j++] = str1.getData()[i];
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,184 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,220 @@
/*
Rafay Ahmad
23I-2526
Assignment 3
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
string input;
cout<<"Enter a string:\n";
getline(cin, input);
String str((char*)input.c_str());
str.trim();
str.print();
cout<<"Length: "<<str.strLength()<<endl;
cout<<"Empty: "<<str.empty()<<endl;
char c;
cout<<"Enter a character to find in the string:\n";
cin>>c;
cout<<"Character found at index: "<<str.charAt(c)<<endl;
char substr[100];
int startIndex, endIndex;
cout<<"Enter a substring to find in the string:\n";
cin>>substr;
cout<<"Enter start index:\n";
cin>>startIndex;
cout<<"Enter end index:\n";
cin>>endIndex;
cout<<"Substring: ";
cout<<str.substring(substr, startIndex, endIndex)<<endl;
return 0;
}

View file

@ -0,0 +1,183 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[str1.strLength()-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<str1.strLength();i++){
if(str1.substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}else{
newStr[j++] = str1.getData()[i];
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,219 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
string input;
cout<<"Enter a string:\n";
getline(cin, input);
String str((char*)input.c_str());
str.trim();
str.print();
cout<<"Length: "<<str.strLength()<<endl;
cout<<"Empty: "<<str.empty()<<endl;
char c;
cout<<"Enter a character to find in the string:\n";
cin>>c;
cout<<"Character found at index: "<<str.charAt(c)<<endl;
char substr[100];
int startIndex, endIndex;
cout<<"Enter a substring to find in the string:\n";
cin>>substr;
cout<<"Enter start index:\n";
cin>>startIndex;
cout<<"Enter end index:\n";
cin>>endIndex;
cout<<"Substring: ";
cout<<str.substring(substr, startIndex, endIndex)<<endl;
return 0;
}

View file

@ -0,0 +1,221 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
string input;
cout<<"Enter a string:\n";
getline(cin, input);
String str((char*)input.c_str());
str.trim();
str.print();
cout<<"Length: "<<str.strLength()<<endl;
cout<<"Empty: "<<str.empty()<<endl;
char c;
cout<<"Enter a character to find in the string:\n";
cin>>c;
cout<<"Character found at index: "<<str.charAt(c)<<endl;
char substr[100];
int startIndex, endIndex;
cout<<"Enter a substring to find in the string:\n";
cin>>substr;
cout<<"Enter start index:\n";
cin>>startIndex;
cout<<"Enter end index:\n";
cin>>endIndex;
cout<<"Substring: ";
str.substring(substr, startIndex, endIndex).print();
return 0;
}

View file

@ -0,0 +1,163 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
this->data = this->substring(start, end);
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,155 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
this->data = this->substring(start, end);
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1 @@
{"version":1,"resource":"file:///home/rafayahmad/Stuff/a3/q6.cpp","entries":[{"id":"l6NA.cpp","timestamp":1711189587031},{"id":"OD1U.cpp","timestamp":1711189606631},{"id":"9Gnj.cpp","timestamp":1711189631205},{"id":"fbZV.cpp","timestamp":1711189665681},{"id":"lXXG.cpp","timestamp":1711189694778},{"id":"g7iV.cpp","timestamp":1711189706188},{"id":"NDJj.cpp","timestamp":1711189747805},{"id":"81pO.cpp","timestamp":1711189781125},{"id":"rzsE.cpp","timestamp":1711189807625},{"id":"jagO.cpp","timestamp":1711189823768},{"id":"6TU9.cpp","timestamp":1711189835818},{"id":"pAOC.cpp","timestamp":1711189852718},{"id":"pXZe.cpp","timestamp":1711189876245},{"id":"ehaS.cpp","timestamp":1711189913181},{"id":"mFr1.cpp","timestamp":1711189970571},{"id":"Kuhf.cpp","timestamp":1711189982115},{"id":"iMkZ.cpp","timestamp":1711190169528},{"id":"6nOP.cpp","timestamp":1711190179938},{"id":"cGEM.cpp","timestamp":1711190199775},{"id":"gGaX.cpp","timestamp":1711190294181},{"id":"O64z.cpp","timestamp":1711191302114},{"id":"xWD9.cpp","timestamp":1711191322774},{"id":"n6jk.cpp","timestamp":1711191354660},{"id":"GQqr.cpp","timestamp":1711191377034},{"id":"OxAt.cpp","timestamp":1711191389804},{"id":"VwkB.cpp","timestamp":1711191411484},{"id":"qatt.cpp","timestamp":1711191430890},{"id":"LA3H.cpp","timestamp":1711191461367},{"id":"AEL2.cpp","timestamp":1711191490904},{"id":"PcMU.cpp","timestamp":1711191506704},{"id":"nF0O.cpp","timestamp":1711191593667},{"id":"JQr0.cpp","timestamp":1711191638601},{"id":"nYKX.cpp","timestamp":1711191689281},{"id":"tuMD.cpp","timestamp":1711191771007},{"id":"th0U.cpp","timestamp":1711191889564},{"id":"9fUN.cpp","timestamp":1711191934920},{"id":"8rni.cpp","timestamp":1711191965754},{"id":"OHfG.cpp","timestamp":1711608140951},{"id":"hBGk.cpp","timestamp":1711608160223},{"id":"M4zo.cpp","timestamp":1711608294623},{"id":"tHEG.cpp","timestamp":1711608359271},{"id":"r4pz.cpp","timestamp":1711794065067},{"id":"5fIX.cpp","timestamp":1711794212297},{"id":"w0HG.cpp","timestamp":1711794254792},{"id":"br1H.cpp","timestamp":1711794270426},{"id":"pU0Q.cpp","timestamp":1711794291940},{"id":"N0Vq.cpp","timestamp":1711794409993},{"id":"nhrf.cpp","timestamp":1711794421473},{"id":"bOm3.cpp","timestamp":1711794455393},{"id":"RcU0.cpp","timestamp":1711869532781}]}

View file

@ -0,0 +1,149 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
for(int i=0;this->data[i] == ' ';i++){
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,149 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size;
for(int i=0;this->data[i] == ' ';i++) start++;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,163 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,230 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
// test all functions
String str("Hello World");
cout<<"String: ";
str.print();
cout<<"Length: "<<str.strLength()<<endl;
cout<<"Empty: "<<str.empty()<<endl;
cout<<"Char at 'W': "<<str.charAt('W')<<endl;
cout<<"Char at 'w': "<<str.charAt('w')<<endl;
cout<<"Data: "<<str.getData()<<endl;
cout<<"Equals 'Hello World': "<<str.equals("Hello World")<<endl;
cout<<"Equals 'hello world': "<<str.equals("hello world")<<endl;
cout<<"Equals Ignore Case 'hello world': "<<str.equalsIgnoreCase("hello world")<<endl;
cout<<"Equals Ignore Case 'Hello World': "<<str.equalsIgnoreCase("Hello World")<<endl;
cout<<"Substring(6, 11): ";
str.substring(6, 11).print();
cout<<"Substring 'World' (2): ";
str.substring("World", 2).print();
cout<<"Substring 'World' (2, 7): ";
str.substring("World", 2, 7).print();
cout<<"Starts with 'Hello': "<<str.startsWith("Hello")<<endl;
cout<<"Ends with 'World': "<<str.endsWith("World")<<endl;
cout<<"Ends with 'world': "<<str.endsWith("world")<<endl;
cout<<"Concatenate '!!!': ";
str.concatenate("!!!");
str.print();
cout<<"Insert '!!!' at 5: ";
str.insert(5, "!!!");
str.print();
cout<<"Remove '!!!': ";
str.remove("!!!");
str.print();
cout<<"Trim: ";
str.trim();
str.print();
cout<<"To Upper Case: ";
str.toUpperCase();
str.print();
cout<<"To Lower Case: ";
str.toLowerCase();
str.print();
return 0;
}

View file

@ -0,0 +1,163 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.data);
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
this->data = this->substring(start, end);
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,151 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
this->data = this->substring(start, end);
}
void toUpperCase(){
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,148 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
for(int i=0;i<this->size;i++){
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,148 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size;
for(int i=0;this->data[i] == ' ';i++) start++;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,162 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
this->toLowerCase();
for(int i=0;str[i]!='\0' && i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
this->data = this->substring(start, end);
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,184 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
// remove all occureces of substr in this
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<str1.strLength();i++){
if(str1.substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[str1.strLength()-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<str1.strLength();i++){
if(str1.substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}else{
newStr[j++] = str1.getData()[i];
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,184 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,183 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,221 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
string input;
cout<<"Enter a string:\n";
getline(cin, input);
String str((char*)input.c_str());
str.trim();
str.print();
cout<<"Length: "<<str.strLength()<<endl;
cout<<"Empty: "<<str.empty()<<endl;
char c;
cout<<"Enter a character to find in the string:\n";
cin>>c;
cout<<"Character found at index: "<<str.charAt(c)<<endl;
char substr[100];
int startIndex, endIndex;
cout<<"Enter a substring to find in the string:\n";
cin>>substr;
cout<<"Enter start index:\n";
cin>>startIndex;
cout<<"Enter end index:\n";
cin>>endIndex;
cout<<"Substring: ";
cout<<str.substring(substr, startIndex, endIndex)<<endl;
return 0;
}

View file

@ -0,0 +1,155 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
this->data = this->substring(start, end);
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,221 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
string input;
cout<<"Enter a string:\n";
getline(cin, input);
String str((char*)input.c_str());
str.trim();
str.print();
cout<<"Length: "<<str.strLength()<<endl;
cout<<"Empty: "<<str.empty()<<endl;
char c;
cout<<"Enter a character to find in the string:\n";
cin>>c;
cout<<"Character found at index: "<<str.charAt(c)<<endl;
char substr[100];
int startIndex, endIndex;
cout<<"Enter a substring to find in the string:\n";
cin>>substr;
cout<<"Enter start index:\n";
cin>>startIndex;
cout<<"Enter end index:\n";
cin>>endIndex;
cout<<"Substring: ";
str.substring(substr, startIndex, endIndex);
return 0;
}

View file

@ -0,0 +1,155 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
this->data = this->substring(start, end);
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i];
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,183 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<str1.strLength();i++){
if(str1.substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}else{
newStr[j++] = str1.getData()[i];
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,191 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
string input;
cout<<"Enter a string:\n";
getline(cin, input);
String str((char*)input.c_str());
return 0;
}

View file

@ -0,0 +1,149 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){ // TODO
for(int i=0;str[i]!='\0' && i<this->size;i++)
if(data[i] != str[i]) return false;
return true;
}
char* substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
this->data = this->substring(start, end);
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,185 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,184 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, this->size).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,184 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,221 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
String str(substr);
for(int i=startIndex;i<this->size;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, this->size).data;
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
String str(substr);
for(int i=startIndex;i<endIndex;i++){
if(this->substring(startIndex, str.strLength()+startIndex).equals(substr)){
return substring(startIndex, endIndex).data;
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[this->size-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<this->size;i++){
if(this->substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}
else{
newStr[j] = str1.getData()[i];
j++;
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
string input;
cout<<"Enter a string:\n";
getline(cin, input);
String str((char*)input.c_str());
str.trim();
str.print();
cout<<"Length: "<<str.strLength()<<endl;
cout<<"Empty: "<<str.empty()<<endl;
char c;
cout<<"Enter a character to find in the string:\n";
cin>>c;
cout<<"Character found at index: "<<str.charAt(c)<<endl;
char substr[100];
int startIndex, endIndex;
cout<<"Enter a substring to find in the string:\n";
cin>>substr;
cout<<"Enter start index:\n";
cin>>startIndex;
cout<<"Enter end index:\n";
cin>>endIndex;
cout<<"Substring: ";
str.substring(substr, startIndex, endIndex).print();
return 0;
}

View file

@ -0,0 +1,184 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class String{
char* data;
int size;
public:
String() : data(nullptr), size(0){}
String(int size) : size(size){
data = new char[size];
}
String(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
this->size = length+1;
data = new char[size];
for(int i=0;i<this->size;i++) data[i] = str[i];
data[size - 1] = '\0';
}
String(const String &str){
this->size = str.size+1;
data = new char[size];
for(int i=0;i<str.size;i++) data[i] = str.data[i];
data[size-1] = '\0';
}
~String(){
delete[] data;
}
int strLength(){
return size;
}
void clear(){
delete[] data;
size = 0;
}
bool empty(){
return size == 0;
}
int charAt(char c){
for(int i=0;i<this->size;i++) if(data[i] == c) return i;
return -1;
}
char* getData(){
return data;
}
bool equals(char* str){
int length = 0;
for(int i=0;str[i]!='\0';i++) length++;
if(length != this->size) return false;
for(int i=0;i<this->size;i++) if(data[i] != str[i]) return false;
return true;
}
bool equalsIgnoreCase(char* str){
String lowerStr(str);
lowerStr.toLowerCase();
this->toLowerCase();
return this->equals(lowerStr.getData());
}
String substring(int startIndex, int endIndex){
char* result = new char[endIndex-startIndex+1];
for(int i=startIndex;i<endIndex;i++) result[i-startIndex] = data[i];
result[endIndex-startIndex] = '\0';
return result;
}
char* substring(char* substr, int startIndex){
char* result;
for(int i=startIndex;i<this->size;i++){
if(this->equals(substr)){
return substring(startIndex, this->size);
}
}
return NULL;
}
char* substring(char* substr, int startIndex, int endIndex){
char* result;
for(int i=startIndex;i<endIndex;i++){
if(this->equals(substr)){
return substring(startIndex, endIndex);
}
}
return NULL;
}
void print(){
if(this->size == 0) cout<<"NULL\n";
else{
for(int i=0;i<this->size;i++) cout<<data[i];
cout<<endl;
}
}
bool startsWith(char* substr) const{
String str1(data);
String str2(substr);
String str3(str1.substring(0, str2.strLength()));
return str3.equals(substr);
}
bool endsWith(char* substr) const{
String str1(substr);
String str2(data);
String str3(str2.substring(str2.strLength()-str1.strLength(), str2.strLength()));
return str3.equals(substr);
}
void concatenate(char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<this->size;i++) newStr[i] = data[i];
for(int i=0;i<str1.strLength();i++) newStr[i+this->size] = str[i];
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void insert(int index, char* str){
String str1(str);
char* newStr = new char[str1.strLength()+this->size+1];
for(int i=0;i<str1.strLength()+this->size;i++){
if(i<index) newStr[i] = data[i];
else if(i<str1.strLength()+index) newStr[i] = str[i-index];
else newStr[i] = data[i-index];
}
newStr[str1.strLength()+this->size] = '\0';
delete[] data;
data = newStr;
this->size += str1.strLength();
}
void remove(char* substr){
// remove all occureces of substr in this
String str1(data);
String str2(substr);
int count = 0;
for(int i=0;i<str1.strLength();i++){
if(str1.substring(i, i+str2.strLength()).equals(substr)){
count++;
}
}
char* newStr = new char[str1.strLength()-count*str2.strLength()+1];
int j = 0;
for(int i=0;i<str1.strLength();i++){
if(str1.substring(i, i+str2.strLength()).equals(substr)){
i += str2.strLength()-1;
}else{
newStr[j++] = str1.getData()[i];
}
}
newStr[j] = '\0';
delete[] data;
data = newStr;
this->size = j;
}
void trim(){
int start = 0, end = this->size-1;
for(int i=0;this->data[i] == ' ';i++) start++;
for(int i=this->size-1;this->data[i] == ' ';i--) end--;
*this = String(this->substring(start, end));
}
void toUpperCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'a'...'z': this->data[i] -= 32;
}
}
}
void toLowerCase(){
for(int i=0;i<this->size;i++){
switch(this->data[i]){
case 'A'...'Z': this->data[i] += 32;
}
}
}
};
int main(){
return 0;
}