Advertisement
Guest User

Untitled

a guest
Feb 7th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. void String::insert(int start, const String& s)
  2. {
  3.         //save old values
  4.         char* temp = new char[size+1];
  5.         strcpy(temp, str);
  6.         unsigned oldSize = size;
  7.  
  8.         //resize
  9.         size += s.size;
  10.         str = new char[size + 1];
  11.  
  12.         //Counter
  13.         unsigned tempCount = 0, // alt
  14.                  sizeCount = 0; // neu
  15.        
  16.         while(tempCount < oldSize)
  17.         {
  18.             //if we reached the insertion-point...
  19.             if(sizeCount == start)
  20.             {
  21.                 //...insert the new string at this position
  22.                 for(unsigned sCount = 0; sCount < s.size; sCount++)
  23.                 {
  24.                     //mit neuen Werten füllen
  25.                     str[sizeCount] = s.str[sCount];
  26.                     sizeCount++;
  27.                 }
  28.             }
  29.  
  30.         //fill with old values
  31.         str[sizeCount] = temp[tempCount];
  32.         sizeCount++;
  33.         tempCount++;
  34.         }
  35.  
  36.         //adding NULL-Byte
  37.         str[size] = '\0';
  38.         delete [] temp;
  39.        
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement