Java tutorial
//package com.java2s; public class Main { public static String genMarkdown(String text) { text = escapeXml(text); while (text.contains("[[")) { String left = text.substring(0, text.indexOf("[[")); String url = text.substring(text.indexOf("[[") + 2, text.indexOf("]]")); String right = text.substring(text.indexOf("]]") + 2); text = left + "<a href=\"" + url + "\">" + url + "</a>" + right; } return text; } public static String escapeXml(String doco) { if (doco == null) return ""; StringBuilder b = new StringBuilder(); for (char c : doco.toCharArray()) { if (c == '<') b.append("<"); else if (c == '>') b.append(">"); else if (c == '&') b.append("&"); else if (c == '"') b.append("""); else b.append(c); } return b.toString(); } }