analysis the position of character is in the XML comment section - Java XML

Java examples for XML:XML Encoding

Description

analysis the position of character is in the XML comment section

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String str = "java2s.com";
        int index = 2;
        System.out.println(isInComment(str, index));
    }//from w  ww .j a v a  2s  .com

    /**
     * analysis the position of character is in the comment section
     * @param String, whole text paragraph
     * @param int, the character index position within text
     * @return booelan, true means position in comment section
     */
    public static boolean isInComment(String str, int index) {
        int strComment = 0;
        int endComment = 0;
        boolean ret = false;
        strComment = str.lastIndexOf("<!--", index);
        if (strComment > -1) {
            endComment = str.lastIndexOf("-->", index);
            if (endComment < strComment) {
                ret = true;
            }
        }

        return (ret);

    }
}

Related Tutorials