List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:MainClass.java
public static void main(String args[]) { String in = "a=1;" + "b=2"; StringTokenizer st = new StringTokenizer(in, "=;"); while (st.hasMoreTokens()) { String key = st.nextToken(); String val = st.nextToken(); System.out.println(key + "\t" + val); }/*from w ww .j a va 2 s.c o m*/ }
From source file:Main.java
public static void main(String[] args) { String temp = "<NOUN>Nitin<NOUN> <NOUN>test<NOUN>"; String finalString = "this is a test"; StringTokenizer x = new StringTokenizer(temp, " "); while (x.hasMoreTokens()) { String token = x.nextToken(); String findword = token.replaceAll("<NOUN>", ""); String findword1 = findword.replaceAll("</NOUN>", ""); String modifiedString = finalString.replaceFirst(findword1, "<NOUN>" + findword1 + "</NOUN>"); finalString = modifiedString;/*from w ww.j a v a 2s.co m*/ } System.out.println(finalString); }
From source file:StringReverse.java
public static void main(String[] argv) { //+//from w ww . j ava 2 s . c om String s = "Father Charles Goes Down And Ends Battle"; // Put it in the stack frontwards Stack myStack = new Stack(); StringTokenizer st = new StringTokenizer(s); while (st.hasMoreTokens()) myStack.push(st.nextElement()); // Print the stack backwards System.out.print('"' + s + '"' + " backwards by word is:\n\t\""); while (!myStack.empty()) { System.out.print(myStack.pop()); System.out.print(' '); } System.out.println('"'); //- }
From source file:Main.java
public static void main(String[] args) { int i = 0;/* w w w .jav a 2 s. co m*/ String str = "one);two);three);four"; StringTokenizer st = new StringTokenizer(str, ");"); String temp[] = new String[st.countTokens()]; while (st.hasMoreTokens()) { temp[i] = st.nextToken(); System.out.println(temp[i]); i++; } }
From source file:SubSupScriptPDF.java
public static void main(String[] args) { Document document = new Document(); try {/* w w w . ja va 2 s .c o m*/ PdfWriter.getInstance(document, new FileOutputStream("SubSupScriptPDF.pdf")); document.open(); String s = "Text Text Text Text Text Text Text Text Text Text Text Text Text Text "; StringTokenizer st = new StringTokenizer(s, " "); float textrise = 6.0f; Chunk c; while (st.hasMoreTokens()) { c = new Chunk(st.nextToken()); c.setTextRise(textrise); c.setUnderline(new Color(0xC0, 0xC0, 0xC0), 0.2f, 0.0f, 0.0f, 0.0f, PdfContentByte.LINE_CAP_BUTT); document.add(c); textrise -= 2.0f; } } catch (Exception ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:Main.java
public static void main(String[] args) { String str = "This is a test, this is another test."; String delimiters = " ,"; // a space and a comma StringTokenizer st = new StringTokenizer(str, delimiters); System.out.println("Tokens using a StringTokenizer:"); String token = null;/*from ww w. j a v a 2 s . c o m*/ while (st.hasMoreTokens()) { token = st.nextToken(); System.out.println(token); } }
From source file:com.ok2c.lightmtp.examples.SendMailExample.java
public static void main(final String[] args) throws Exception { if (args.length < 3) { System.out.println("Usage: sender recipient1[;recipient2;recipient3;...] file"); System.exit(0);/* ww w .j av a 2s. c o m*/ } String sender = args[0]; List<String> recipients = new ArrayList<String>(); StringTokenizer tokenizer = new StringTokenizer(args[1], ";"); while (tokenizer.hasMoreTokens()) { String s = tokenizer.nextToken(); s = s.trim(); if (s.length() > 0) { recipients.add(s); } } File src = new File(args[2]); if (!src.exists()) { System.out.println("File '" + src + "' does not exist"); System.exit(0); } DeliveryRequest request = new BasicDeliveryRequest(sender, recipients, new FileSource(src)); MailUserAgent mua = new DefaultMailUserAgent(TransportType.SMTP, IOReactorConfig.DEFAULT); mua.start(); try { InetSocketAddress address = new InetSocketAddress("localhost", 2525); Future<DeliveryResult> future = mua.deliver(new SessionEndpoint(address), 0, request, null); DeliveryResult result = future.get(); System.out.println("Delivery result: " + result); } finally { mua.shutdown(); } }
From source file:Main.java
public static void main(String[] args) { StringTokenizer st = new StringTokenizer("tutorial from java2s.com"); // counting tokens System.out.println("Total tokens : " + st.countTokens()); // checking tokens while (st.hasMoreTokens()) { System.out.println("Next token : " + st.nextToken()); }//from w w w . j av a2 s.co m }
From source file:info.bitoo.utils.BiToorrentRemaker.java
public static void main(String[] args) throws IOException, TOTorrentException { CommandLineParser parser = new PosixParser(); CommandLine cmd = null;/*from w ww . j a va2s. c o m*/ try { cmd = parser.parse(createCommandLineOptions(), args); } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); } StringTokenizer stLocations = new StringTokenizer(cmd.getOptionValue("l"), "|"); List locations = new ArrayList(stLocations.countTokens()); while (stLocations.hasMoreTokens()) { URL locationURL = new URL((String) stLocations.nextToken()); locations.add(locationURL.toString()); } String torrentFileName = cmd.getOptionValue("t"); File torrentFile = new File(torrentFileName); TOTorrentDeserialiseImpl torrent = new TOTorrentDeserialiseImpl(torrentFile); torrent.setAdditionalListProperty("alternative locations", locations); torrent.serialiseToBEncodedFile(torrentFile); }
From source file:edu.gslis.ts.RunQuery.java
public static void main(String[] args) { try {/* w w w .java 2 s .c o m*/ // Get the commandline options Options options = createOptions(); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); String inputPath = cmd.getOptionValue("input"); String eventsPath = cmd.getOptionValue("events"); String stopPath = cmd.getOptionValue("stop"); int queryId = Integer.valueOf(cmd.getOptionValue("query")); List<String> ids = FileUtils.readLines(new File(inputPath + File.separator + "ids.txt")); Stopper stopper = new Stopper(stopPath); Map<Integer, FeatureVector> queries = readEvents(eventsPath, stopper); FeatureVector query = queries.get(queryId); Pairtree ptree = new Pairtree(); Bag<String> words = new HashBag<String>(); for (String streamId : ids) { String ppath = ptree.mapToPPath(streamId.replace("-", "")); String inpath = inputPath + File.separator + ppath + File.separator + streamId + ".xz"; // System.out.println(inpath); File infile = new File(inpath); InputStream in = new XZInputStream(new FileInputStream(infile)); TTransport inTransport = new TIOStreamTransport(new BufferedInputStream(in)); TBinaryProtocol inProtocol = new TBinaryProtocol(inTransport); inTransport.open(); final StreamItem item = new StreamItem(); while (true) { try { item.read(inProtocol); // System.out.println("Read " + item.stream_id); } catch (TTransportException tte) { // END_OF_FILE is used to indicate EOF and is not an exception. if (tte.getType() != TTransportException.END_OF_FILE) tte.printStackTrace(); break; } } // Do something with this document... String docText = item.getBody().getClean_visible(); StringTokenizer itr = new StringTokenizer(docText); while (itr.hasMoreTokens()) { words.add(itr.nextToken()); } inTransport.close(); } for (String term : words.uniqueSet()) { System.out.println(term + ":" + words.getCount(term)); } } catch (Exception e) { e.printStackTrace(); } }