Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q4009 How do I parse a comma delimited string?

irt.org | Knowledge Base | Java | Q4009 [ previous next ]

Q4009 How do I parse a comma delimited string?

Use the StringTokenizer object, the following is a snippet of code which fills in 4 values (Open, High, Low and Close) in respective variables from an string ohlc which is passed as a parameter to the method

public Candle(String ohlc){
      /**
       * The StringTokenizer class lets us separate ohlc
       * using custom separators. I used a space, a colon, a comma,
       * and a semicolon as separators.
       */
      StringTokenizer st=new StringTokenizer(ohlc," :,;");
      open=(new Double(st.nextToken())).doubleValue();
      high=(new Double(st.nextToken())).doubleValue();
      low=(new Double(st.nextToken())).doubleValue();
      close=(new Double(st.nextToken())).doubleValue();
      
   }

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.