escape String by char to another char - Android java.lang

Android examples for java.lang:String Escape

Description

escape String by char to another char

Demo Code

import android.content.Context;
import android.content.res.AssetManager;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main{

    public static String escapeString(String s, String escapeChars,
            char prefix) {
        StringBuffer sb = new StringBuffer(s.length());
        for (int ich = 0; ich < s.length(); ich++) {
            char ch = s.charAt(ich);
            if (escapeChars.indexOf(ch) != -1) {
                sb.append(prefix);/*from w ww.j a  v a  2 s .c om*/
                sb.append(ch);
            } else if (ch == '\n') {
                sb.append("\n");
            } else {
                sb.append(ch);
            }
        }
        return sb.toString();
    }

}

Related Tutorials