Here you can find the source of charsToEntities(String str)
Parameter | Description |
---|---|
str | The string |
public static String charsToEntities(String str)
//package com.java2s; /**/* w ww . ja v a 2 s.c o m*/ * Copyright 2011 The ARIES Consortium (http://www.ariesonline.org) and * www.integratedmodelling.org. This file is part of Thinklab. Thinklab is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Thinklab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Thinklab. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Converts <, >, & in the string to their HTML entity * equivalents. * @param str The string * @since jEdit 4.2pre1 */ public static String charsToEntities(String str) { StringBuffer buf = new StringBuffer(str.length()); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); switch (ch) { case '<': buf.append("<"); break; case '>': buf.append(">"); break; case '&': buf.append("&"); break; default: buf.append(ch); break; } } return buf.toString(); } }