Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. /*
  2.  * Destructivly strip a bounded substring out of a string
  3.  * remove (), <>, [], {} etc and their contents
  4.  *
  5.  * Returns 1 (Success) or 0 (Fail)
  6.  */
  7. int stripout(char *_caStBuff, char _leftboundary, char _rightboundary) {
  8.     int         iLoop,
  9.             iStrLen,
  10.             iLeft,
  11.             iRight ;
  12.  
  13.     iLeft   = (-1) ;
  14.     iRight  = (-1) ;
  15.     iStrLen = strlen( _caStrBuff ) ;
  16.  
  17.     if ( iStrLen < 1 ) {
  18.         // I can't help you
  19.         return 0 ;
  20.     }
  21.  
  22.     // find boundery indexs
  23.     for (iLoop = 0; iLoop < iStrLen; ++iLoop) {
  24.         if (_caStrBuff[iLoop] == _leftboundary) {
  25.             iLeft = iLoop ;
  26.         } else if (_caStrBuff[iLoop] == _rightboundary) {
  27.             iRight = iLoop ;
  28.         } else {
  29.         }
  30.     } // find indexs
  31.  
  32.     if ((iLeft > 0) && (iRight > iLeft) ) {
  33.         strcpy( &_caStrBuff[ iLeft-1 ], &_caStrBuff[ iRight+1 ] ) ;
  34.         return 1 ;
  35.     } else if ( (iLeft == 0) && (iRight > iLeft) ) {
  36.         strcpy( _caStrBuff, &_caStrBuff[ iRight+1 ] ) ;
  37.         return 1 ;
  38.     } else {
  39.     }
  40.    
  41.     return 0 ;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement