Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String addEscpage(String str) {
        char[] cs = str.toCharArray();
        StringBuilder sb = new StringBuilder("\"");
        int length = cs.length;
        for (int i = 0; i < length; i++) {
            if (cs[i] == '\"' || cs[i] == '\t' || cs[i] == '\n') {
                sb.append("\\");
            }
            sb.append(cs[i]);
        }
        sb.append("\"");
        return sb.toString();
    }
}