Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Escapes string for XML.
     *
     * @param in input string
     * @return escaped string
     */
    private static String escape(String in) {
        StringBuilder sb = new StringBuilder();
        for (char c : in.toCharArray()) {
            switch (c) {
            case '&':
                sb.append("&");
                break;
            case 0xA0: // \n
                sb.append(" ");
                break;
            case '<':
                sb.append("&lt;");
                break;
            case '>':
                sb.append("&gt;");
                break;
            case '"':
                sb.append("&quot;");
                break;
            default:
                sb.append(c);
            }
        }
        return sb.toString();
    }
}