Java String Strip stripTags(final String tagged)

Here you can find the source of stripTags(final String tagged)

Description

strip Tags

License

Open Source License

Parameter

Parameter Description
tagged a parameter

Return

String

Declaration

public static String stripTags(final String tagged) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Manchester Institute of Biotechnology
 * University of Manchester/* w ww.  j  av a  2  s. c  o  m*/
 * Manchester M1 7ND
 * United Kingdom
 * 
 * Copyright (C) 2013 University of Manchester
 * 
 * This program is released under the Academic Free License ("AFL") v3.0.
 * (http://www.opensource.org/licenses/academic.php)
 *******************************************************************************/

import java.util.*;

public class Main {
    /**
     * 
     */
    private static final String COLLECTION_SEPARATOR = ", ";
    /**
     * 
     */
    private static final int COLLECTION_SEPARATOR_LENGTH = COLLECTION_SEPARATOR
            .length();

    /**
     * 
     * @param tagged
     * @return String
     */
    public static String stripTags(final String tagged) {
        final StringBuffer stripped = new StringBuffer();
        boolean inTag = false;

        for (int i = 0; i < tagged.length(); i++) {
            final char c = tagged.charAt(i);

            if (c == '<') {
                inTag = true;
                continue;
            }

            if (c == '>') {
                inTag = false;
                continue;
            }

            if (inTag) {
                continue;
            }

            stripped.append(c);
        }

        return stripped.toString().trim();
    }

    /**
     * 
     * @param values
     * @return String
     */
    public static String toString(final Collection<?> values) {
        final StringBuilder builder = new StringBuilder();

        for (Object value : values) {
            builder.append(value);
            builder.append(COLLECTION_SEPARATOR);
        }

        if (values.size() > 0) {
            builder.setLength(builder.length()
                    - COLLECTION_SEPARATOR_LENGTH);
        }

        return builder.toString();
    }
}

Related

  1. stripClassFromClassName(String className)
  2. stripExtension(String filename)
  3. stripLastElement(String str)
  4. stripLeadingSlash(String str)
  5. stripNamespaceDeclarations(String xml)
  6. stripTags(String html)
  7. stripTags(String in)
  8. stripTrailingChar(String input, char c)
  9. stripUnsupportedChars(String str)