List of usage examples for java.lang String getChars
public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin)
From source file:MainClass.java
public static void main(String[] arg) { String text = "To be or not to be"; char[] textArray = new char[3]; text.getChars(9, 12, textArray, 0); for (char ch : textArray) { System.out.println(ch);//from w ww. j a v a 2 s. co m } }
From source file:Main.java
public static void main(String args[]) throws IOException { String source = "test"; char buffer[] = new char[source.length()]; source.getChars(0, source.length(), buffer, 0); FileWriter f0 = new FileWriter("file1.txt"); for (int i = 0; i < buffer.length; i += 2) { f0.write(buffer[i]);//from ww w . ja v a 2s . c om } f0.close(); FileWriter f1 = new FileWriter("file2.txt"); f1.write(buffer); f1.close(); FileWriter f2 = new FileWriter("file3.txt"); f2.write(buffer, buffer.length - buffer.length / 4, buffer.length / 4); f2.close(); }
From source file:Main.java
public static void main(String[] args) { String str = "java2s.com"; System.out.println(str);//from w w w. j a va 2s . co m char[] chararr = new char[30]; str.getChars(2, 6, chararr, 0); System.out.print("Value of character array : "); System.out.println(chararr); }
From source file:CharArrayWriterDemo.java
public static void main(String args[]) throws IOException { CharArrayWriter f = new CharArrayWriter(); String s = "This should end up in the array"; char buf[] = new char[s.length()]; s.getChars(0, s.length(), buf, 0); f.write(buf);//w w w.j ava2 s. c om System.out.println(f.toString()); char c[] = f.toCharArray(); for (int i = 0; i < c.length; i++) { System.out.print(c[i]); } FileWriter f2 = new FileWriter("test.txt"); f.writeTo(f2); f2.close(); f.reset(); for (int i = 0; i < 3; i++) f.write('X'); }
From source file:Main.java
public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String tmp = br.readLine(); int length = tmp.length(); char c[] = new char[length]; tmp.getChars(0, length, c, 0); CharArrayReader input1 = new CharArrayReader(c); int i;/*from w w w.j a v a2 s .co m*/ System.out.print("input1 is:"); while ((i = input1.read()) != -1) { System.out.print((char) i); } }
From source file:MainClass.java
public static void main(String args[]) { String s = "This is an demo."; int start = 1; int end = 5;/*from w w w.ja v a 2 s . co m*/ char buf[] = new char[end - start]; s.getChars(start, end, buf, 0); System.out.println(buf); }
From source file:Snippet19.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Text text = new Text(shell, SWT.BORDER | SWT.V_SCROLL); text.setBounds(10, 10, 200, 200);//from w w w . ja va2s .c o m text.addListener(SWT.Verify, new Listener() { public void handleEvent(Event e) { String string = e.text; char[] chars = new char[string.length()]; string.getChars(0, chars.length, chars, 0); for (int i = 0; i < chars.length; i++) { if (!('0' <= chars[i] && chars[i] <= '9')) { e.doit = false; return; } } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Main.java
public static void main(String args[]) throws IOException { String tmp = "abcdefghijklmnopqrstuvwxyz"; int length = tmp.length(); char c[] = new char[length]; tmp.getChars(0, length, c, 0); CharArrayReader input1 = new CharArrayReader(c); CharArrayReader input2 = new CharArrayReader(c, 0, 5); int i;/*from w w w .j a v a 2 s .c om*/ while ((i = input1.read()) != -1) { System.out.print((char) i); } while ((i = input2.read()) != -1) { System.out.print((char) i); } }
From source file:getCharsDemo.java
public static void main(String args[]) { String s = "This is a demo of the getChars method."; int start = 10; int end = 14; char buf[] = new char[end - start]; s.getChars(start, end, buf, 0); System.out.println(buf);// w w w . j a v a 2 s . c om }
From source file:Main.java
public static void main(String args[]) { String s = "This is a test string from java2s.com."; int start = 10; int end = 14; char buf[] = new char[end - start]; s.getChars(start, end, buf, 0); System.out.println(buf);//from w w w. j a v a 2 s. com }