List of usage examples for java.lang String toCharArray
public char[] toCharArray()
From source file:net.sf.taverna.t2.activities.spreadsheet.SpreadsheetUtils.java
/** * Converts a column label to a (0 based) column index. * <p>// w w w . j a v a 2 s .c om * Label must match the format [A-Z]+ for result to be valid. * * @param column * the column label * @return the (0 based) column index */ public static int getColumnIndex(String column) { int result = -1; char a = 'A' - 1; char[] chars = column.toCharArray(); for (int i = 0; i < chars.length; i++) { int pos = (chars[i] - a); result += pos * Math.pow(26, chars.length - i - 1); } return result; }
From source file:ProducerAndConsumerTool.java
private static String[] splitComponents(String str) { List<String> l = new ArrayList<String>(); int last = 0; int depth = 0; char chars[] = str.toCharArray(); for (int i = 0; i < chars.length; i++) { switch (chars[i]) { case '(': depth++;/*from w ww . j a va 2 s . c om*/ break; case ')': depth--; break; case ',': if (depth == 0) { String s = str.substring(last, i); l.add(s); last = i + 1; } break; default: } } String s = str.substring(last); if (s.length() != 0) { l.add(s); } String rc[] = new String[l.size()]; l.toArray(rc); return rc; }
From source file:Main.java
/** * Trims several consecutive characters into one. * /*from w w w. j a v a 2s .co m*/ * @param str * the string to trim consecutive characters of * @param ch * the character to trim down * @return the newly trimmed down string */ public static final String trimConsecutiveToOne(String str, char ch) { if ((null == str) || (str.length() == 0)) { return ""; } char[] buffer = str.toCharArray(); char[] newbuf = new char[buffer.length]; int pos = 0; boolean same = false; for (int i = 0; i < buffer.length; i++) { char car = buffer[i]; if (car == ch) { if (same) { continue; } else { same = true; newbuf[pos++] = car; } } else { same = false; newbuf[pos++] = car; } } return new String(newbuf, 0, pos); }
From source file:com.easemob.dataexport.utils.StringUtils.java
public static byte[] hexToBytes(String hexString) { char[] hex = hexString.toCharArray(); int length = hex.length / 2; byte[] rawData = new byte[length]; for (int i = 0; i < length; i++) { int high = Character.digit(hex[i * 2], 16); int low = Character.digit(hex[i * 2 + 1], 16); int value = (high << 4) | low; if (value > 127) { value -= 256;/*from ww w. j a v a2s . c om*/ } rawData[i] = (byte) value; } return rawData; }
From source file:info.novatec.testit.livingdoc.util.NameUtils.java
public static String humanize(String s) { StringBuilder literal = new StringBuilder(); char[] chars = s.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (Character.isUpperCase(c) && i > 0) { literal.append(' '); literal.append(Character.toLowerCase(c)); } else {//w ww . ja v a 2 s . co m literal.append(c); } } return literal.toString(); }
From source file:Main.java
private static String toVisualString(String src) { boolean cutFlg = false; if (null == src) { return null; }/*from w ww .j a v a 2s . co m*/ char[] chr = src.toCharArray(); if (null == chr) { return null; } int i = 0; for (; i < chr.length; i++) { if (chr[i] > 127) { chr[i] = 0; cutFlg = true; break; } } if (cutFlg) { return new String(chr, 0, i); } else { return src; } }
From source file:Main.java
public static String[] split(String fileName) { StringBuffer nombre = new StringBuffer(); StringBuffer extension = new StringBuffer(); boolean ext = false; char[] cars = fileName.toCharArray(); for (int i = 0; i < cars.length; i++) { if (cars[i] == '.') { if (ext) { nombre.append('.'); nombre.append(extension.toString()); extension = new StringBuffer(); } else { ext = true;/*w w w.j av a 2 s .co m*/ } } else { if (ext) { extension.append(cars[i]); } else { nombre.append(cars[i]); } } } String[] split = new String[2]; split[0] = nombre.toString(); split[1] = extension.toString(); return split; }
From source file:com.enonic.cms.core.portal.PrettyPathNameCreator.java
public static String convertName(String str) { return convertName(str.toCharArray()); }
From source file:com.myapp.common.AES4MEncrypt.java
public static byte[] string2AnslBytes(String str) { StringBuilder sb = new StringBuilder(); for (char c : str.toCharArray()) { sb.append(","); sb.append((int) c); }/*from ww w . j a va 2s. com*/ String anslStr = sb.substring(1); byte[] b = new byte[anslStr.length()]; int i = 0; for (char c : anslStr.toCharArray()) { b[i++] = (byte) c; } return b; }
From source file:Main.java
/** * Method to encode the xml text./*from w w w . j av a2s.c o m*/ * @param rawtext string of the xml text. * @return the encode string. */ public static String xmlEncode(String rawtext) { // Now turn that UTF-8 string into something "safe" String rdfString = "<?xml version='1.0' encoding='ISO-8859-1'?>\n"; char[] sbuf = rawtext.toCharArray(); int lastPos = 0; int pos = 0; while (pos < sbuf.length) { char ch = sbuf[pos]; if (!(ch == '\n' || (ch >= ' ' && ch <= '~'))) { if (pos > lastPos) { String range = new String(sbuf, lastPos, pos - lastPos); rdfString += range; } rdfString += "&#" + (int) ch + ";"; lastPos = pos + 1; } pos++; } if (pos > lastPos) { String range = new String(sbuf, lastPos, pos - lastPos); rdfString += range; } return rdfString; }