extract Encoding from XML String - Java XML

Java examples for XML:XML Encoding

Description

extract Encoding from XML String

Demo Code


//package com.java2s;

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

    private static String extractEncoding(String hdr) {
        int i = hdr.indexOf("encoding="); //$NON-NLS-1$
        if (i == -1)
            return null;
        hdr = hdr.substring(i + 9);
        char sep = hdr.charAt(0);
        hdr = hdr.substring(1);
        i = hdr.indexOf(sep);
        if (i == -1)
            return null;
        return hdr.substring(0, i);
    }
}

Related Tutorials