Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void String::insert(int start, const String& s)
- {
- //save old values
- char* temp = new char[size+1];
- strcpy(temp, str);
- unsigned oldSize = size;
- //resize
- size += s.size;
- str = new char[size + 1];
- //Counter
- unsigned tempCount = 0, // alt
- sizeCount = 0; // neu
- while(tempCount < oldSize)
- {
- //if we reached the insertion-point...
- if(sizeCount == start)
- {
- //...insert the new string at this position
- for(unsigned sCount = 0; sCount < s.size; sCount++)
- {
- //mit neuen Werten füllen
- str[sizeCount] = s.str[sCount];
- sizeCount++;
- }
- }
- //fill with old values
- str[sizeCount] = temp[tempCount];
- sizeCount++;
- tempCount++;
- }
- //adding NULL-Byte
- str[size] = '\0';
- delete [] temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement