Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Karlsruhe Institute of Technology, Germany * Technical University Darmstadt, Germany * Chalmers University of Technology, Sweden * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Technical University Darmstadt - initial API and implementation and/or initial documentation *******************************************************************************/ public class Main { /** * Removes all tags from the given text. * @param text The text to remove tags from. * @return The text without tags. */ public static String removeTags(String text) { if (text != null) { StringBuffer sb = new StringBuffer(); char[] signs = text.toCharArray(); boolean inTag = false; boolean inAttribute = false; for (char sign : signs) { if (!inTag) { if (sign == '<') { inTag = true; } else { sb.append(sign); } } else { if (sign == '>' && !inAttribute) { inTag = false; inAttribute = false; } else if (sign == '\'' || sign == '"') { inAttribute = !inAttribute; } } } return sb.toString(); } else { return null; } } }