String formatting under a certain character [closed]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-8















I'm making a textbook indexer and I'm formatting the output file. there are periods between the word and its frequency.



desired textfile output:



word..............25:
word...............3:
word...............2:


I'm trying to get the lines to be aligned to the : but I can't get it under the semicolon if the numbers are more than 1 digit.



Does anybody have any ideas for java string formatting for the desired output?



for reference the biggest word is 23 characters and it's frequency is 1.










share|improve this question















closed as too broad by Hovercraft Full Of Eels, jww, EJoshuaS, Sotirios Delimanolis, Makyen Nov 17 '18 at 5:12


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 3





    First try solving it yourself, and then if still stuck, post your attempt here in your question. This involves simple math and a for loop, and I have faith that you'll either come up with a solution or something very close if you try just a little.

    – Hovercraft Full Of Eels
    Nov 17 '18 at 2:45













  • Why would I need a for loop? I'm trying to use Java's String format function. So far I have this: String.format("%s%23d:", getWord(),count ).replace(' ', '.') + lineNumbers; I'm continuing to mess around with it but no dice.

    – Dart Feld
    Nov 17 '18 at 2:54













  • Make sure the font you use for your text file is a non-proportional font which would be a font whose letters and characters each occupy the same amount of horizontal space otherwise achieving a descent lineup will be difficult. Courier or MonoSpace821 BT are such fonts.

    – DevilsHnd
    Nov 17 '18 at 3:01






  • 1





    @DevilsHnd: generally text in a text file is font-agnostic.

    – Hovercraft Full Of Eels
    Nov 17 '18 at 3:04











  • Please post the current code that you have and we can give you hints a to how to approach the problem. We're not going to hand you an answer to an obvious homework question.

    – John Kim
    Nov 17 '18 at 3:05


















-8















I'm making a textbook indexer and I'm formatting the output file. there are periods between the word and its frequency.



desired textfile output:



word..............25:
word...............3:
word...............2:


I'm trying to get the lines to be aligned to the : but I can't get it under the semicolon if the numbers are more than 1 digit.



Does anybody have any ideas for java string formatting for the desired output?



for reference the biggest word is 23 characters and it's frequency is 1.










share|improve this question















closed as too broad by Hovercraft Full Of Eels, jww, EJoshuaS, Sotirios Delimanolis, Makyen Nov 17 '18 at 5:12


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 3





    First try solving it yourself, and then if still stuck, post your attempt here in your question. This involves simple math and a for loop, and I have faith that you'll either come up with a solution or something very close if you try just a little.

    – Hovercraft Full Of Eels
    Nov 17 '18 at 2:45













  • Why would I need a for loop? I'm trying to use Java's String format function. So far I have this: String.format("%s%23d:", getWord(),count ).replace(' ', '.') + lineNumbers; I'm continuing to mess around with it but no dice.

    – Dart Feld
    Nov 17 '18 at 2:54













  • Make sure the font you use for your text file is a non-proportional font which would be a font whose letters and characters each occupy the same amount of horizontal space otherwise achieving a descent lineup will be difficult. Courier or MonoSpace821 BT are such fonts.

    – DevilsHnd
    Nov 17 '18 at 3:01






  • 1





    @DevilsHnd: generally text in a text file is font-agnostic.

    – Hovercraft Full Of Eels
    Nov 17 '18 at 3:04











  • Please post the current code that you have and we can give you hints a to how to approach the problem. We're not going to hand you an answer to an obvious homework question.

    – John Kim
    Nov 17 '18 at 3:05














-8












-8








-8








I'm making a textbook indexer and I'm formatting the output file. there are periods between the word and its frequency.



desired textfile output:



word..............25:
word...............3:
word...............2:


I'm trying to get the lines to be aligned to the : but I can't get it under the semicolon if the numbers are more than 1 digit.



Does anybody have any ideas for java string formatting for the desired output?



for reference the biggest word is 23 characters and it's frequency is 1.










share|improve this question
















I'm making a textbook indexer and I'm formatting the output file. there are periods between the word and its frequency.



desired textfile output:



word..............25:
word...............3:
word...............2:


I'm trying to get the lines to be aligned to the : but I can't get it under the semicolon if the numbers are more than 1 digit.



Does anybody have any ideas for java string formatting for the desired output?



for reference the biggest word is 23 characters and it's frequency is 1.







java






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 17:12









EJoshuaS

7,440103051




7,440103051










asked Nov 17 '18 at 2:44









Dart FeldDart Feld

64




64




closed as too broad by Hovercraft Full Of Eels, jww, EJoshuaS, Sotirios Delimanolis, Makyen Nov 17 '18 at 5:12


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as too broad by Hovercraft Full Of Eels, jww, EJoshuaS, Sotirios Delimanolis, Makyen Nov 17 '18 at 5:12


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 3





    First try solving it yourself, and then if still stuck, post your attempt here in your question. This involves simple math and a for loop, and I have faith that you'll either come up with a solution or something very close if you try just a little.

    – Hovercraft Full Of Eels
    Nov 17 '18 at 2:45













  • Why would I need a for loop? I'm trying to use Java's String format function. So far I have this: String.format("%s%23d:", getWord(),count ).replace(' ', '.') + lineNumbers; I'm continuing to mess around with it but no dice.

    – Dart Feld
    Nov 17 '18 at 2:54













  • Make sure the font you use for your text file is a non-proportional font which would be a font whose letters and characters each occupy the same amount of horizontal space otherwise achieving a descent lineup will be difficult. Courier or MonoSpace821 BT are such fonts.

    – DevilsHnd
    Nov 17 '18 at 3:01






  • 1





    @DevilsHnd: generally text in a text file is font-agnostic.

    – Hovercraft Full Of Eels
    Nov 17 '18 at 3:04











  • Please post the current code that you have and we can give you hints a to how to approach the problem. We're not going to hand you an answer to an obvious homework question.

    – John Kim
    Nov 17 '18 at 3:05














  • 3





    First try solving it yourself, and then if still stuck, post your attempt here in your question. This involves simple math and a for loop, and I have faith that you'll either come up with a solution or something very close if you try just a little.

    – Hovercraft Full Of Eels
    Nov 17 '18 at 2:45













  • Why would I need a for loop? I'm trying to use Java's String format function. So far I have this: String.format("%s%23d:", getWord(),count ).replace(' ', '.') + lineNumbers; I'm continuing to mess around with it but no dice.

    – Dart Feld
    Nov 17 '18 at 2:54













  • Make sure the font you use for your text file is a non-proportional font which would be a font whose letters and characters each occupy the same amount of horizontal space otherwise achieving a descent lineup will be difficult. Courier or MonoSpace821 BT are such fonts.

    – DevilsHnd
    Nov 17 '18 at 3:01






  • 1





    @DevilsHnd: generally text in a text file is font-agnostic.

    – Hovercraft Full Of Eels
    Nov 17 '18 at 3:04











  • Please post the current code that you have and we can give you hints a to how to approach the problem. We're not going to hand you an answer to an obvious homework question.

    – John Kim
    Nov 17 '18 at 3:05








3




3





First try solving it yourself, and then if still stuck, post your attempt here in your question. This involves simple math and a for loop, and I have faith that you'll either come up with a solution or something very close if you try just a little.

– Hovercraft Full Of Eels
Nov 17 '18 at 2:45







First try solving it yourself, and then if still stuck, post your attempt here in your question. This involves simple math and a for loop, and I have faith that you'll either come up with a solution or something very close if you try just a little.

– Hovercraft Full Of Eels
Nov 17 '18 at 2:45















Why would I need a for loop? I'm trying to use Java's String format function. So far I have this: String.format("%s%23d:", getWord(),count ).replace(' ', '.') + lineNumbers; I'm continuing to mess around with it but no dice.

– Dart Feld
Nov 17 '18 at 2:54







Why would I need a for loop? I'm trying to use Java's String format function. So far I have this: String.format("%s%23d:", getWord(),count ).replace(' ', '.') + lineNumbers; I'm continuing to mess around with it but no dice.

– Dart Feld
Nov 17 '18 at 2:54















Make sure the font you use for your text file is a non-proportional font which would be a font whose letters and characters each occupy the same amount of horizontal space otherwise achieving a descent lineup will be difficult. Courier or MonoSpace821 BT are such fonts.

– DevilsHnd
Nov 17 '18 at 3:01





Make sure the font you use for your text file is a non-proportional font which would be a font whose letters and characters each occupy the same amount of horizontal space otherwise achieving a descent lineup will be difficult. Courier or MonoSpace821 BT are such fonts.

– DevilsHnd
Nov 17 '18 at 3:01




1




1





@DevilsHnd: generally text in a text file is font-agnostic.

– Hovercraft Full Of Eels
Nov 17 '18 at 3:04





@DevilsHnd: generally text in a text file is font-agnostic.

– Hovercraft Full Of Eels
Nov 17 '18 at 3:04













Please post the current code that you have and we can give you hints a to how to approach the problem. We're not going to hand you an answer to an obvious homework question.

– John Kim
Nov 17 '18 at 3:05





Please post the current code that you have and we can give you hints a to how to approach the problem. We're not going to hand you an answer to an obvious homework question.

– John Kim
Nov 17 '18 at 3:05












1 Answer
1






active

oldest

votes


















-1














Since in the comment, the OP attempted to use String.format(), here is an approach to consider. Rather than trying to get the number to align right with the "%23d", align the word and the count separately.



String.format("%-23s%2d:", getWord(), count);


The %-23d will format the getWord() in 23 spaces, left aligned, then the %2d will right align the "count".



Example output:



Hello...................9:
Goodbye................42:
whatever...............17:


Note I just used the same .replace() approach as the OP for quickness sake.



See this attempt here at ideone.com






share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    -1














    Since in the comment, the OP attempted to use String.format(), here is an approach to consider. Rather than trying to get the number to align right with the "%23d", align the word and the count separately.



    String.format("%-23s%2d:", getWord(), count);


    The %-23d will format the getWord() in 23 spaces, left aligned, then the %2d will right align the "count".



    Example output:



    Hello...................9:
    Goodbye................42:
    whatever...............17:


    Note I just used the same .replace() approach as the OP for quickness sake.



    See this attempt here at ideone.com






    share|improve this answer




























      -1














      Since in the comment, the OP attempted to use String.format(), here is an approach to consider. Rather than trying to get the number to align right with the "%23d", align the word and the count separately.



      String.format("%-23s%2d:", getWord(), count);


      The %-23d will format the getWord() in 23 spaces, left aligned, then the %2d will right align the "count".



      Example output:



      Hello...................9:
      Goodbye................42:
      whatever...............17:


      Note I just used the same .replace() approach as the OP for quickness sake.



      See this attempt here at ideone.com






      share|improve this answer


























        -1












        -1








        -1







        Since in the comment, the OP attempted to use String.format(), here is an approach to consider. Rather than trying to get the number to align right with the "%23d", align the word and the count separately.



        String.format("%-23s%2d:", getWord(), count);


        The %-23d will format the getWord() in 23 spaces, left aligned, then the %2d will right align the "count".



        Example output:



        Hello...................9:
        Goodbye................42:
        whatever...............17:


        Note I just used the same .replace() approach as the OP for quickness sake.



        See this attempt here at ideone.com






        share|improve this answer













        Since in the comment, the OP attempted to use String.format(), here is an approach to consider. Rather than trying to get the number to align right with the "%23d", align the word and the count separately.



        String.format("%-23s%2d:", getWord(), count);


        The %-23d will format the getWord() in 23 spaces, left aligned, then the %2d will right align the "count".



        Example output:



        Hello...................9:
        Goodbye................42:
        whatever...............17:


        Note I just used the same .replace() approach as the OP for quickness sake.



        See this attempt here at ideone.com







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 '18 at 3:31









        KevinOKevinO

        3,50142031




        3,50142031

















            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python