private static final char[] legalChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" .toCharArray();
private static Vector nodes = new Vector();
/** * Split string into multiple strings * * @param original * Original string * @param separator * Separator string in original string * @return Splitted string array */ public static String[] split(String original, String separator) { nodes.removeAllElements(); // Parse nodes into vector int index = original.indexOf(separator); while (index >= 0) { nodes.addElement(original.substring(0, index)); original = original.substring(index + separator.length()); index = original.indexOf(separator); } // Get the last node nodes.addElement(original);
// Create splitted string array String[] result = new String[nodes.size()]; if (nodes.size() > 0) { for (int loop = 0; loop < nodes.size(); loop++) result[loop] = (String) nodes.elementAt(loop); } return result; }
/* * Replace all instances of a String in a String. @param s String to alter. * @param f String to look for. @param r String to replace it with, or null * to just remove it. */ public static String replace(String s, String f, String r) { if (s == null) return s; if (f == null) return s; if (r == null) r = "";
int index01 = s.indexOf(f); while (index01 != -1) { s = s.substring(0, index01) + r + s.substring(index01 + f.length()); index01 += r.length(); index01 = s.indexOf(f, index01); } return s; }
/** * Method removes HTML tags from given string. * * @param text * Input parameter containing HTML tags (eg. <b>cat</b>) * @return String without HTML tags (eg. cat) */ public static String removeHtml(String text) { try { int idx = text.indexOf("<"); if (idx == -1) return text;
/** Base64 encode the given data */ public static String encode(byte[] data) { int start = 0; int len = data.length; StringBuffer buf = new StringBuffer(data.length * 3 / 2);
int end = len - 3; int i = start; int n = 0;
while (i <= end) { int d = ((((int) data[i]) & 0x0ff) << 16) | ((((int) data[i + 1]) & 0x0ff) << 8) | (((int) data[i + 2]) & 0x0ff);