title: How can non-ASCII characters be removed from a string?
body: <p>I have strings <code>&quot;A função&quot;</code>, <code>&quot;Ãugent&quot;</code> in which I need to replace characters like <code>ç</code>, <code>ã</code>, and <code>Ã</code> with empty strings.</p>
  <p>How can I remove those non-ASCII characters from my string?</p>
  <p>I have attempted to implement this using the following function, but it is not working properly.  One problem is that the unwanted characters are getting replaced by the space character.</p>
  <pre class="lang-java prettyprint-override"><code>public static String matchAndReplaceNonEnglishChar(String tmpsrcdta) {
      String newsrcdta = null;
      char array[] = Arrays.stringToCharArray(tmpsrcdta);
      if (array == null)
          return newsrcdta;
  
      for (int i = 0; i &lt; array.length; i++) {
          int nVal = (int) array[i];
          boolean bISO =
                  // Is character ISO control
                  Character.isISOControl(array[i]);
          boolean bIgnorable =
                  // Is Ignorable identifier
                  Character.isIdentifierIgnorable(array[i]);
          // Remove tab and other unwanted characters..
          if (nVal == 9 || bISO || bIgnorable)
              array[i] = ' ';
          else if (nVal &gt; 255)
              array[i] = ' ';
      }
      newsrcdta = Arrays.charArrayToString(array);
  
      return newsrcdta;
  }
  </code></pre>