remove from UTF16 - Android java.lang

Android examples for java.lang:String Unicode

Description

remove from UTF16

Demo Code

/*//from   w  w w .  j a v  a  2  s.com
 *******************************************************************************
 * Copyright (C) 1996-2015, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
 */
import sun.text.normalizer.UTF16;
import android.icu.text.UnicodeSet;

public class Main {
  public static String remove(String source, UnicodeSet removals) {
    StringBuffer result = new StringBuffer();
    int cp;
    for (int i = 0; i < source.length(); i += UTF16.getCharCount(cp)) {
      cp = UTF16.charAt(source, i);
      if (!removals.contains(cp))
        UTF16.append(result, cp);
    }
    return result.toString();
  }
}

Related Tutorials