Results 1 to 3 of 3

Thread: problem with '\t' in java

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default problem with '\t' in java

    Hello,
    I'm reading a file line by line and I need to print it out but a strange thing:
    Qt Code:
    1. String [] token = line.split("\\t");
    2. .....
    3. System.out.println( token[0] + '\t' + token[1] );
    To copy to clipboard, switch view to plain text mode 
    the otput is something about:
    Qt Code:
    1. DDDDD 3333333 //if there are 5 characters appears many spaces
    2. DDDD 3333333 //this should be ok
    3. EEEEE 33333333
    To copy to clipboard, switch view to plain text mode 
    why that? I need only a tab between them? thanks
    Regards

  2. #2
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: problem with '\t' in java

    I need a help from the best here......
    I noticed that problem appear in the console of eclipse only; instead of print out, I tried to print to a file and the tab problem disappear but in the file the tab is something like 10 spaces (' ')

    Why all this (I'm working under windows)?
    thanks,
    Last edited by mickey; 19th May 2009 at 18:23.
    Regards

  3. #3
    Join Date
    Jul 2009
    Posts
    13
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with '\t' in java

    Change your regular expression from \\t to \\s+. \\t matches a single tab. \\s matches any whitespace ( tabs, spaces, etc ). The + modifier specifies "at least one". You probably see a difference in output spacing due to the font of each output - i.e. one of the output fonts is monospaced and the other output font is not monospaced. If you must have the output the same, use String.format("%8s\t%8s", token[0], token[1]) where 8 means the requested width.

Similar Threads

  1. Replies: 1
    Last Post: 23rd April 2009, 09:05
  2. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  3. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  4. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.