Java HTML Entities htmlEntities(String s)

Here you can find the source of htmlEntities(String s)

Description

Escapes special html characters in a string, namely &, <, > and ".

License

Open Source License

Parameter

Parameter Description
s a string

Return

the escaped string

Declaration

public static String htmlEntities(String s) 

Method Source Code

//package com.java2s;
/*****************************************************************************
 *
 * Copyright 2012-2016 SkillPro Consortium
 *
 * Author: PDE, FZI, pde@fzi.de/*from  w w w .  j  a  v a  2s.c o m*/
 *
 * Date of creation: 2012-2016
 *
 * Module: AMS Server
 *
 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This file is part of the AMS (Asset Management System), which has been developed
 * at the PDE department of the FZI, Karlsruhe. It is part of the SkillPro Framework,
 * which is is developed in the SkillPro project, funded by the European FP7
 * programme (Grant Agreement 287733).
 *
 * The SkillPro Framework is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * The SkillPro Framework 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 Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with the SkillPro Framework. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

public class Main {
    /**
     * Escapes special html characters in a string, namely &amp;, &lt;, &gt; and &quot;. 
     * @param s a string
     * @return the escaped string
     */
    public static String htmlEntities(String s) {
        s = s.replace("&", "&amp;");
        s = s.replace("<", "&lt;");
        s = s.replace(">", "&gt;");
        s = s.replace("\"", "&quot;");
        return s;
    }
}

Related

  1. htmlEntites(String str)
  2. htmlEntites(String str)
  3. htmlEntities(String text)
  4. htmlEntityToString(String dataStr)