Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: space in the Name

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default space in the Name

    Hi,

    I am trying to read a dat file. each tab has one specific data. but unfortunately some date has space on it. like I am reading "ABC A" I want this to be one token reading a line but it considers ABC as one token and A another token. Is there any way to read ABA A together regardless of their space.

    Thank you


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,931
    Thanks
    55
    Thanked 2,353 Times in 2,324 Posts

    Default Re: space in the Name

    What method and what class are you using to read and parse the Strings?

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: space in the Name

    public TreeMap countyDistanceDataParser() {
            TreeMap treeOfCountyDistance = new TreeMap();
            String record = null;
            String key = null;
     
            try {
                FileReader fileReader = new FileReader(this.countyDistanceData);
                BufferedReader buffer = new BufferedReader(fileReader);
                record = new String();
                StringTokenizer stringToken;
                String s1 = buffer.readLine();
     
                int count = 0; // the arrays of th shortest paths start from one
     
                while ((record = buffer.readLine()) != null) {
                    //Logger.out.println("record: " + record);
                    stringToken = new StringTokenizer(record);
                    CountyDistance cntDist = new CountyDistance();
                    count = count + 1;
                    int counter = 0;
                    while (stringToken.hasMoreTokens()) {
                        String str = stringToken.nextToken();
                        counter = counter + 1;
     
                        if (counter == 1) {
                            cntDist.setOrgFips("f" + str);
                        } else if (counter == 2) {
                            cntDist.setDestFips("f" + str);
                        } else if (counter == 3) {
                            cntDist.setOrgName(str);
                        } else if (counter == 4) {
                            cntDist.setDestName(str);
                        } else if (counter == 5) {
                            Float gcd = new Float(str);
                            float gcdF = gcd.floatValue();
                            cntDist.setGCD(gcdF);
                        } else if (counter == 6) {
                            Float hmi = new Float(str);
                            float hmiF = hmi.floatValue();
                            cntDist.setH_Mi(hmiF);
                        } else if (counter == 7) {
                            Float himp = new Float(str);
                            float himpF = himp.floatValue();
                            cntDist.setH_Imp(himpF);
                        } else if (counter == 8) {
                            Float Rmi = new Float(str);
                            float RmiF = Rmi.floatValue();
                            cntDist.setR_Mi(RmiF);
                        } else if (counter == 9) {
                            Float Rimp = new Float(str);
                            float RimpF = Rimp.floatValue();
                            cntDist.setR_Imp(RimpF);
                        } else if (counter == 10) {
                            Float wmi = new Float(str);
                            float wmiF = wmi.floatValue();
                            cntDist.setW_Mi(wmiF);
                        } else if (counter == 11) {
                            Float wimp = new Float(str);
                            float wimpF = wimp.floatValue();
                            cntDist.setW_Imp(wimpF);
                        } else if (counter == 12) {
                            Float HRHimp = new Float(str);
                            float HRHimpF = HRHimp.floatValue();
                            cntDist.setHRH_Imp(HRHimpF);
                        }
     
     
     
                    }
     
                    // add the intersection to the tree
                    key = cntDist.getOrgFips() + cntDist.getDestFips();
                    treeOfCountyDistance.put(key, cntDist);
     
     
                }
     
     
     
            } catch (IOException e) {
                // catch possible io errors from readLine()
                System.out.println("IOException error: ");
                e.printStackTrace();
            }
     
            return treeOfCountyDistance;
        }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,931
    Thanks
    55
    Thanked 2,353 Times in 2,324 Posts

    Default Re: space in the Name

    One of The constructors for the StringTokenizer class takes a String of delimiters.
    Have you tried that?

    You don't need this whole program to do the test. You only need s small program with a String with the data as you want to parse. Create a StringTokenizer instance, passing it the string and then printout the tokens that are returned to see if they are what you want.
    Last edited by Norm; July 8th, 2011 at 04:50 PM.

Similar Threads

  1. [SOLVED] TicTacToe program - Space taken?
    By Actinistia in forum Java Theory & Questions
    Replies: 6
    Last Post: May 3rd, 2011, 12:06 AM
  2. Space Monkey Returns
    By SPACE MONKEY in forum Member Introductions
    Replies: 1
    Last Post: February 17th, 2011, 09:59 AM
  3. perm gen space
    By gargdevender in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 20th, 2010, 03:55 AM
  4. Java Heap Space
    By aussiemcgr in forum Java Theory & Questions
    Replies: 4
    Last Post: September 8th, 2010, 06:05 PM
  5. print space
    By brainTuner in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 1st, 2010, 07:09 PM