How to parse this output and separate each field/word

前端 未结 3 850
醉话见心
醉话见心 2021-01-22 18:12

This is Akshatha. I\'m stuck in parsing the following data. I want to fetch each word individually. Can I have a sample code so that I can proceed

 RTRV-HDR   RH         


        
相关标签:
3条回答
  • 2021-01-22 18:45

    I would try String.split(). Something like this...
    String [] words;
    words = line.split("\s+");

    The above splits the string on whitespace.

    0 讨论(0)
  • 2021-01-22 18:54

    Use BufferedReader to read your file (or input stream) thusly.

    Then use StringTokenizer to split each line into tokens thisly

    I'm not providing a ready-to-use code here because I think you'd learn better by combining the above examples into a working code yourself.

    0 讨论(0)
  • 2021-01-22 19:00

    How about using a Stringtokenizer to fetch each word?

    import java.util.*;
    public class ReverseWords {
        public static void main( String args[] ) {
            String s = "Go to the main menu. Quick!";
            StringTokenizer tokens = new StringTokenizer(s);
            StringBuffer ab;
    
            while (tokens.hasMoreTokens()){
                ab = new StringBuffer (tokens.nextToken());
                // do your processing
            }
            System.out.println();
        }
    }
    
    0 讨论(0)
提交回复
热议问题