List of usage examples for java.text StringCharacterIterator StringCharacterIterator
public StringCharacterIterator(String text)
From source file:Main.java
public static void main(String[] argv) throws Exception { CharacterIterator it = new StringCharacterIterator("abcd"); for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it.previous()) { System.out.println(ch);/*from w ww . ja va 2 s . c om*/ } }
From source file:Main.java
public static void main(String[] argv) throws Exception { CharacterIterator it = new StringCharacterIterator("abcd"); ((StringCharacterIterator) it).setText("efgh"); char ch = it.current(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { CharacterIterator it = new StringCharacterIterator("abcd"); int begin = 5; int end = 9;/* www. j a v a 2s .c o m*/ int pos = 6; it = new StringCharacterIterator("abcd efgh ijkl", begin, end, pos); char ch = it.current(); System.out.println(ch); ch = it.last(); System.out.println(ch); }
From source file:Main.java
public static void main(String[] argv) throws Exception { CharacterIterator it = new StringCharacterIterator("abcd"); char ch = it.first(); ch = it.current();//w w w . j a va 2s. c o m ch = it.next(); ch = it.current(); ch = it.last(); int pos = it.getIndex(); ch = it.next(); pos = it.getIndex(); ch = it.previous(); ch = it.setIndex(1); }
From source file:Main.java
public static void main(String[] args) { CharacterIterator it = new StringCharacterIterator(text); for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it.previous()) { System.out.print(ch);// ww w .j a v a2s . c o m } }
From source file:Main.java
public static void main(String[] args) { String text = "The quick brown fox jumps over the lazy dog"; CharacterIterator it = new StringCharacterIterator(text); int vowels = 0; int consonants = 0; for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) { if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { vowels = vowels + 1;/* w w w . j a va 2 s. c o m*/ } else if (ch != ' ') { consonants = consonants + 1; } } System.out.println("Number of vowels: " + vowels); System.out.println("Number of consonants: " + consonants); }
From source file:Main.java
public static String escapeTextForXML(String aText) { final StringBuilder result = new StringBuilder(); final StringCharacterIterator iterator = new StringCharacterIterator(aText); char character = iterator.current(); while (character != CharacterIterator.DONE) { if (character == '<') { result.append("<"); } else if (character == '>') { result.append(">"); } else if (character == '\"') { result.append("""); } else if (character == '\'') { result.append("'"); } else if (character == '&') { result.append("&"); } else {//from ww w. j a va2s .co m //the char is not a special one //add it to the result as is result.append(character); } character = iterator.next(); } return result.toString(); }
From source file:Main.java
static String escape(String input) { if (input == null) { return null; }//from ww w . ja v a 2 s . co m StringBuilder result = new StringBuilder(); StringCharacterIterator iterator = new StringCharacterIterator(input); char character = iterator.current(); while (character != CharacterIterator.DONE) { if (character == '<') { result.append("<"); } else if (character == '>') { result.append(">"); } else if (character == '\"') { result.append("""); } else if (character == '\'') { result.append("'"); } else if (character == '&') { result.append("&"); } else { result.append(character); } character = iterator.next(); } return result.toString(); }
From source file:Main.java
public static String escape(String input) { if (input == null) { return null; }//from ww w . j a v a 2s . com StringBuilder result = new StringBuilder(); StringCharacterIterator iterator = new StringCharacterIterator(input); char character = iterator.current(); while (character != CharacterIterator.DONE) { if (character == '<') { result.append("<"); } else if (character == '>') { result.append(">"); } else if (character == '\"') { result.append("""); } else if (character == '\'') { result.append("'"); } else if (character == '&') { result.append("&"); } else { result.append(character); } character = iterator.next(); } return result.toString(); }
From source file:Main.java
protected static boolean checkNamePart(String s) { if (s.length() == 0) return true; CharacterIterator cIter = new StringCharacterIterator(s); char ch = cIter.first(); if (!checkNameStartChar(ch)) return false; return checkNameTail(cIter); }