Remove phonetic characters or string from a content - Java java.lang

Java examples for java.lang:String Algorithm

Introduction

The following code shows how to Remove phonetic characters or string from a content

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String text = "java2s.com";
        System.out.println(removePhonetic(text));
    }//from  w  w  w. j a v  a 2  s  . c om

    /**
     * <p>Remove phonetic characters or string from a content</p>
     * @param text input content
     * @return content cleaned up from phonetic characters.
     */
    public static String removePhonetic(final String text) {
        String content = text;

        int indexParenthesisOpen = text.indexOf("(");
        if (indexParenthesisOpen != -1) {
            if (text.charAt(indexParenthesisOpen + 1) == '/'
                    || text.charAt(indexParenthesisOpen + 2) == '/') {
                int indexParenthesisEnd = text.indexOf(")");
                if (indexParenthesisEnd != -1) {
                    StringBuilder buf = new StringBuilder(text.substring(0,
                            indexParenthesisOpen));
                    buf.append(text.substring(indexParenthesisEnd + 2));
                    content = buf.toString();
                }
            }
        }
        return content;
    }
}

Related Tutorials