List of usage examples for java.lang String toCharArray
public char[] toCharArray()
From source file:Main.java
public static Integer calculateCheckSumFor(String message) { Integer byteSum = 0;//from www .j a v a 2s . c om for (Character character : message.toCharArray()) { byteSum += (int) character; } return byteSum % 256; }
From source file:Main.java
public static String checkEmoticons(String name) { char[] chars = name.toCharArray(); int index;// ww w .j av a 2 s .co m char ch1; char ch2; index = 0; StringBuilder builder = new StringBuilder(); while (index < chars.length) { ch1 = chars[index]; if ((int) ch1 == 0xD83C) { ch2 = chars[index + 1]; if ((int) ch2 >= 0xDF00 && (int) ch2 <= 0xDFFF) { index += 2; continue; } } else if ((int) ch1 == 0xD83D) { ch2 = chars[index + 1]; if ((int) ch2 >= 0xDC00 && (int) ch2 <= 0xDDFF) { index += 2; continue; } } builder.append(ch1); ++index; } builder.trimToSize(); // remove trailing null characters return builder.toString(); }
From source file:Main.java
/** Get 7-bit ASCII character array from input String. The lower 7 bits of each character in the input string is assumed to be the ASCII character value./* ww w. j a v a 2 s . c o m*/ Hexadecimal - Character | 00 NUL| 01 SOH| 02 STX| 03 ETX| 04 EOT| 05 ENQ| 06 ACK| 07 BEL| | 08 BS | 09 HT | 0A NL | 0B VT | 0C NP | 0D CR | 0E SO | 0F SI | | 10 DLE| 11 DC1| 12 DC2| 13 DC3| 14 DC4| 15 NAK| 16 SYN| 17 ETB| | 18 CAN| 19 EM | 1A SUB| 1B ESC| 1C FS | 1D GS | 1E RS | 1F US | | 20 SP | 21 ! | 22 " | 23 # | 24 $ | 25 % | 26 & | 27 ' | | 28 ( | 29 ) | 2A * | 2B + | 2C , | 2D - | 2E . | 2F / | | 30 0 | 31 1 | 32 2 | 33 3 | 34 4 | 35 5 | 36 6 | 37 7 | | 38 8 | 39 9 | 3A : | 3B ; | 3C < | 3D = | 3E > | 3F ? | | 40 @ | 41 A | 42 B | 43 C | 44 D | 45 E | 46 F | 47 G | | 48 H | 49 I | 4A J | 4B K | 4C L | 4D M | 4E N | 4F O | | 50 P | 51 Q | 52 R | 53 S | 54 T | 55 U | 56 V | 57 W | | 58 X | 59 Y | 5A Z | 5B [ | 5C \ | 5D ] | 5E ^ | 5F _ | | 60 ` | 61 a | 62 b | 63 c | 64 d | 65 e | 66 f | 67 g | | 68 h | 69 i | 6A j | 6B k | 6C l | 6D m | 6E n | 6F o | | 70 p | 71 q | 72 r | 73 s | 74 t | 75 u | 76 v | 77 w | | 78 x | 79 y | 7A z | 7B { | 7C | | 7D } | 7E ~ | 7F DEL| */ public static byte[] getAsciiBytes(String input) { char[] c = input.toCharArray(); byte[] b = new byte[c.length]; for (int i = 0; i < c.length; i++) b[i] = (byte) (c[i] & 0x007F); return b; }
From source file:Main.java
public static List<Integer> convertOXYLByteArr2List(byte[] bytes) { if (bytes != null && bytes.length > 0) { List<Integer> oxygenLongList = new ArrayList<>(); String oxyl = new String(bytes); char[] oxylChar = oxyl.toCharArray(); for (int i = 0; i < oxylChar.length; i++) { int oxygen = oxylChar[i]; oxygenLongList.add(oxygen);/*from w ww . j ava 2 s.c om*/ } return oxygenLongList; } return null; }
From source file:Main.java
public static boolean isBalanced(String in) { Stack<Character> st = new Stack<Character>(); for (char chr : in.toCharArray()) { switch (chr) { case '{': case '(': case '[': st.push(chr);//from ww w . j av a 2 s . c om break; case ']': if (st.isEmpty() || st.pop() != '[') return false; break; case ')': if (st.isEmpty() || st.pop() != '(') return false; break; case '}': if (st.isEmpty() || st.pop() != '{') return false; break; } } return st.isEmpty(); }
From source file:Main.java
@NonNull private static String trimEnd(@NonNull String str, char character) { char[] val = str.toCharArray(); int len = val.length; while ((0 < len) && (val[len - 1] == character)) { len--;/* www . j ava2 s. com*/ } return ((len < val.length)) ? str.substring(0, len) : str; }
From source file:Main.java
/** * Trims string by the given character.//from w w w. j a va2s . c om * if char is a space character, then is more useful to use String.trim(). * @param str - string to trim. * @param trimChar - char to check. * @return trimmed string. */ public static String trim(String str, char trimChar) { char[] value = str.toCharArray(); int start = 0, length = value.length; while ((start < length) && (value[start] == trimChar)) { start++; } while ((start < length) && (value[length - 1] == trimChar)) { length--; } return ((start > 0) || (length < value.length)) ? str.substring(start, length) : str; }
From source file:Main.java
public static String Decrypt(String toDecrypt, String key) { char[] chars = toDecrypt.toCharArray(); char[] newChars = new char[chars.length]; for (int i = 0; i < chars.length; i++) { if (chars[i] > 31 && chars[i] < 240) { char c = '?'; for (int j = 0; j < key.length(); j++) { if (key.charAt(j) == chars[i]) { c = (char) (j + 32); break; }//from w ww .ja v a 2 s. co m } newChars[i] = c; } else if (chars[i] == 240) { newChars[i] = '"'; } else { newChars[i] = chars[i]; } } return new String(newChars); }
From source file:Main.java
public static boolean checkNameChese(String name) { boolean res = true; char[] cTemp = name.toCharArray(); for (int i = 0; i < name.length(); i++) { if (!isChinese(cTemp[i])) { res = false;/*from w w w .j a va2 s . com*/ break; } } return res; }
From source file:Main.java
public static String escapeXml(String text) { char[] textChars = text.toCharArray(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < textChars.length; i++) { char c = textChars[i]; switch (c) { case '<': sb.append(LT, 0, 4);// w w w .j ava2 s.co m break; case '>': sb.append(GT, 0, 4); break; case '&': sb.append(AMP, 0, 5); break; case '"': sb.append(QUOT, 0, 6); break; case '\'': sb.append(APOS, 0, 6); break; default: sb.append(c); } } return sb.toString(); }