![]() |
|
#1
|
|||
|
|||
Simple Text Indenter, Help.I'm writing a simple text indenter for an assignment. The point of it is to enter in command line arguments that will provide an input file, output file, max characters per line and amount of spaced to indent by. It's pretty simple in the sense that it just adds spaces to the left of the line, and wrapping the words if it exceeds the maximum character per line, which is given by the user.
For example, the file: Lets Test This with a width of 10 and a indent of 17 should output: (10spaces)Lets (10spaces)Test (10spaces)This Currently my output looks like: (10spaces)lets (10spaces)tes (10spaces)t this And as I add more words, it gets slightly more askew. The function following is what alters the input string. The input string contains the entire input file, spaces is a string that contains the number of spaces equal to the indent the user specified. Width is the maximum characters per line: JAVA Code:
|
|||
|
#2
|
||||
|
||||
Re: Simple Text Indenter, Help.I'm confused as to the difference of 'width' and 'indent' in the original information... If you have a string of spaces, why the width?
Anyway, here's another way to work with the input and spaces without using 'width'. JAVA Code:
This was called using: JAVA Code:
Code:
Note, though, that my example ASSUMES that the input string only has single-spacing, and does not account for multiple spaces, nor leading spaces, nor trailing spaces -- so having these situations would be extra handling that will need consideration. HTH __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! Last edited by TurboPT : 04-Jun-2009 at 08:56.
|
|
#3
|
|||
|
|||
Re: Simple Text Indenter, Help.I guess my explanation was off. Width should be the maximum amount of characters in a line including the magnitude of spaces. For example say the indent (or in this function spaces.length()) is 5 and width is 20, then each line can only have a maximum of 15 characters with 5 spaces preceding them. So the point of my wSpace was to search through and find the last space that was less then width so I could wrap the words. Hope this makes it a bit more clear?
Edit: I was able to solve it. For the longest time I had: JAVA Code:
JAVA Code:
|
|
#4
|
|||
|
|||
Re: Simple Text Indenter, Help.then for mine , how to read from the source file to write to a output file by 10 character per line , and next line 10 character and so on..
JAVA Code:
Last edited by admin : 11-Nov-2009 at 05:32.
Reason: Please insert your example Java codes between [JAVA] and [/JAVA] tags
|
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Power Calibration Error In Nero Fix (hopefully) | matt3678 | Computer Hardware Forum | 60 | 20-Aug-2009 06:04 |
| A program that calculates the number of characters in the text file | et21zero | Java Forum | 5 | 28-Apr-2008 13:04 |
| Simple text file I/O question | brookeville | C++ Forum | 7 | 08-Mar-2005 14:19 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 11:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 12:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The