Find a Unicode in a given String and returns a List with the indices. - Java java.lang

Java examples for java.lang:String Unicode

Description

Find a Unicode in a given String and returns a List with the indices.

Demo Code

//package com.java2s;
import java.util.ArrayList;

public class Main {
    public static void main(String[] argv) {
        String sequence = "java2s.com";
        System.out.println(extractUnicode(sequence));
    }//from  ww w .  ja v a2 s.c o  m

    /**
     * 
     * Find a Unicode in a given String and returns a List with the indices.
     * 
     * @param sequence
     * @return
     * @author DanielAl
     */
    public static ArrayList<Integer> extractUnicode(String sequence) {
        ArrayList<Integer> unicodeStart = new ArrayList<Integer>();
        int help = 0;
        while (help < sequence.length()) {
            if (sequence.substring(help).startsWith("\\U+")) {
                help = sequence.indexOf("\\U+", help);
                unicodeStart.add(help);
                help += 8;
            } else
                help++;
        }
        return unicodeStart;
    }
}

Related Tutorials