@Nonnegative
  public static int replaceMultipleTo (@Nullable final char [] aInput,
                                       @Nonnegative final int nOfs,
                                       @Nonnegative final int nLen,
                                       @Nonnull final char [] aSearchChars,
                                       @Nonnull final char [] [] aReplacementStrings,
                                       @Nonnull final Writer aTarget) throws IOException
  {
    if (aInput != null)
      ValueEnforcer.isArrayOfsLen (aInput, nOfs, nLen);
    ValueEnforcer.notNull (aSearchChars, "SearchChars");
    ValueEnforcer.notNull (aReplacementStrings, "ReplacementStrings");
    ValueEnforcer.isEqual (aSearchChars.length, aReplacementStrings.length, "array length mismatch");
    ValueEnforcer.notNull (aTarget, "Target");

    if (aInput == null || aInput.length == 0 || nLen == 0)
      return 0;

    if (aSearchChars.length == 0)
    {
      // No modifications required
      aTarget.write (aInput, nOfs, nLen);
      return 0;
    }

    // for all input string characters
    int nFirstNonReplace = nOfs;
    int nInputIndex = nOfs;
    int nTotalReplacements = 0;
    final int nMaxSearchChars = aSearchChars.length;
    for (int i = 0; i < nLen; ++i)
    {
      final char cInput = aInput[nOfs + i];
      for (int nPatternIndex = 0; nPatternIndex < nMaxSearchChars; nPatternIndex++)
      {
        if (cInput == aSearchChars[nPatternIndex])
        {
          if (nFirstNonReplace < nInputIndex)
            aTarget.write (aInput, nFirstNonReplace, nInputIndex - nFirstNonReplace);
          nFirstNonReplace = nInputIndex + 1;
          aTarget.write (aReplacementStrings[nPatternIndex]);
          ++nTotalReplacements;
          break;
        }
      }
      nInputIndex++;
    }
    if (nFirstNonReplace < nInputIndex)
      aTarget.write (aInput, nFirstNonReplace, nInputIndex - nFirstNonReplace);
    return nTotalReplacements;
  }
@ Nonnegative public static int replaceMultipleTo ( @ Nullable final char [ ] aInput , @ Nonnegative final int nOfs , @ Nonnegative final int nLen , @ Nonnull final char [ ] aSearchChars , @ Nonnull final char [ ] [ ] aReplacementStrings , @ Nonnull final Writer aTarget ) throws IOException { if ( aInput != null ) ValueEnforcer . isArrayOfsLen ( aInput , nOfs , nLen ) ; ValueEnforcer . notNull ( aSearchChars , "SearchChars" ) ; ValueEnforcer . notNull ( aReplacementStrings , "ReplacementStrings" ) ; ValueEnforcer . isEqual ( aSearchChars . length , aReplacementStrings . length , "array length mismatch" ) ; ValueEnforcer . notNull ( aTarget , "Target" ) ; if ( aInput == null || aInput . length == 0 || nLen == 0 ) return 0 ; if ( aSearchChars . length == 0 ) { aTarget . write ( aInput , nOfs , nLen ) ; return 0 ; } int nFirstNonReplace = nOfs ; int nInputIndex = nOfs ; int nTotalReplacements = 0 ; final int nMaxSearchChars = aSearchChars . length ; for ( int i = 0 ; i < nLen ; ++ i ) { final char cInput = aInput [ nOfs + i ] ; for ( int nPatternIndex = 0 ; nPatternIndex < nMaxSearchChars ; nPatternIndex ++ ) { if ( cInput == aSearchChars [ nPatternIndex ] ) { if ( nFirstNonReplace < nInputIndex ) aTarget . write ( aInput , nFirstNonReplace , nInputIndex - nFirstNonReplace ) ; nFirstNonReplace = nInputIndex + 1 ; aTarget . write ( aReplacementStrings [ nPatternIndex ] ) ; ++ nTotalReplacements ; break ; } } nInputIndex ++ ; } if ( nFirstNonReplace < nInputIndex ) aTarget . write ( aInput , nFirstNonReplace , nInputIndex - nFirstNonReplace ) ; return nTotalReplacements ; }
Specialized version of {@link #replaceMultiple(String, char[], char[][])}
where the object where the output should be appended is passed in as a
parameter. This has the advantage, that not length calculation needs to take
place!

@param aInput
The input char array. May be <code>null</code>.
@param nOfs
Offset into input array. Must be &ge; 0.
@param nLen
Number of characters from input array. Must be &ge; 0.
@param aSearchChars
The characters to replace.
@param aReplacementStrings
The new strings to be inserted instead. Must have the same array
length as aPatterns.
@param aTarget
Where the replaced objects should be written to. May not be
<code>null</code>.
@return The number of replacements performed. Always &ge; 0.
@throws IOException
In case writing to the Writer fails