Java String Normalize normalize(String text)

Here you can find the source of normalize(String text)

Description

Removes diacritics from UTF-8

License

Open Source License

Parameter

Parameter Description
text a parameter

Return

lower case version of text with all diacritic marks removed

Declaration

public static String normalize(String text) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.Normalizer;

public class Main {
    /**/*w w w .  jav  a  2  s. c om*/
     * Removes diacritics from UTF-8
     * @param text
     * @return lower case version of text with all diacritic marks removed
     */
    public static String normalize(String text) {
        String result = text;
        try {
            while (result.length() > 1
                    && !Character.isAlphabetic(result.charAt(0))) {
                if (result.length() > 1) {
                    result = result.substring(1, result.length());
                }
            }
            result = Normalizer.normalize(result.toLowerCase(),
                    Normalizer.Form.NFD);
            result = result.replaceAll(
                    "[\\p{InCombiningDiacriticalMarks}]", "");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}

Related

  1. normalize(String string)
  2. normalize(String string)
  3. normalize(String text)
  4. normalize(String text)
  5. normalize(String text)
  6. normalize(String uri)
  7. normalize(String value)
  8. normalize(String value, Locale locale)
  9. normalizeCutter(String cutter, int numDigits)