Guest User

Untitled

a guest
May 10th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public final class StringBuilderUtils
  2. {
  3.     //StringBuilder doesn't have a decent replace method
  4.     public static void replaceAll( final StringBuilder sb, final String search, final String replace )
  5.     {
  6.         Validate.notNull( sb );
  7.         Validate.notEmpty( search );
  8.         Validate.notNull( replace );
  9.  
  10.         while ( true )
  11.         {
  12.             final int start = sb.indexOf( search );
  13.             if ( start == -1 ) break;
  14.  
  15.             final int end = start + search.length();
  16.             sb.replace( start, end, replace );
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment