I need to create text files and have the ability to control if the text is left or right justified using Go.
I found tab writer but I don't want columns. The text needs to flow freely.
Any suggestions?
You are very limited in the kinds of formatting you can perform within an ASCII text file. There are no ASCII control characters to say that a block of text will be justified in a certain way. You are either relying on a text viewer to interpret a custom syntax as formatting (see the Markdown format) or you are adding spaces to explicitly create the formatting you want on each line.
For the latter, you can insert spaces in front of each line to simulate justification. To do this, you'll need to pick a fixed number of characters per line (e.g. 40 characters) as the basis of your formatting. Note that this maximum line width won't necessarily match the size of the screen in whatever text viewing app your user has.
The left-justification algorithm is basically a word-wrapping algorithm. See Best word wrap algorithm? for that.
The right-justification algorithm is word-wrapping again, but with an intermediate step: Have the word-wrapping function return your text split into word-wrapped lines first. And then pad the start of each line with a count of spaces equal to the count of characters you had remaining to fit inside of the maximum line width.
So say your source text is "There is no justification for this statement!" and your maximum line width is 15 characters. The left-justification algorithm will output this:
There is no
justification
for this
statement!
...and the right-justification algorithm will output this:
There is no
justification
for this
statement!
If you want to change the maximum line width, then you need to run the algorithm again to reflow the text with a new maximum line width.
Related
I'm attempting to parse a file without any sort of specification to guide me. I plan to split a section of this file into variable names, but I'm not sure how the fields are delimited. Clearly there is a pattern in the way the delimiters change...could someone point me in the right direction?
Here's the data I'm interested in (spaces added by me for clarity):
#EEFDAAH TFLBFile CM ExecutionName EL FileContents GI %reserved IJ &ReadCount KE vTest B#CQETMV#Dmain#Ž¾àÅU
Full file (minus some invisible control characters):
MFP214DTest
JA
BMExecutionNameLFileContents
BCEAƒSTCF01TFLBFileTestRead0f36c096fa0~1~2~1~2~0~0~0~0~0~0~0~0~0~0~0~0~0~0~TFLBFile~TFLBFile~~0~0~2~0~0~0~0~1~0~0~0~0~0~0~ExecutionName~ExecutionName~0~0~0~0~0~0~0~0~0~0~0~0~0~0~0~1~0~0~0~0~FileContents~FileContents~0~0~0~0~0~0~0~0~0~0~0~0~0~0~0~1~0~0~0~0~0~1~~0~2~'Test'~15~0~1~0~FQ_dbopenwithfieldsDG_dbreadHprintoutFAHJ#A#WSHSJSGSASDSFSLQNhSHSJSGSISPQRhSESHQThSBTKf#EEFDAAHTFLBFileCMExecutionNameELFileContentsGI%reservedIJ&ReadCountKEvTestB#CQETMV#Dmain#Ž¾àÅU
It may have been better if you had posted one or two more records, and and hex as well. You firstly need to identify record types if they differ. It does indeed look like the leading fields might be handled differently, a record level header, they look space delimited. Try assuming there is a fixed number of fields here. If this fails, there may be different record types and included data may be conditional upon a map or type at the beginning of the record. It may be possible the fields can be read in arbitrary sequence similarly to argv[] elements as value pairs. Architecture would also be useful information, trailing bytes look suspiciously binary..
I faced with issue that sometimes when I created custom formula-fields on Salesforce objects I couldn't save it, the reason of it was limitation in 5000 characters for such type of field.
The main trouble is that when I copied content of formula to any notepad which can calculate number of characters I saw, that there was less than 5000 characters. After some investigations I found that mentions of other formula-fields and also some methods, like TODAY(), can implicitly increase number of characters. In this way the real length will be more than number of character that you type.
My question - how can I see the real amount of formula-field characters and how to know which parts of formula adds extra-amount?
The code in a Formula Field can exceed the maximum number of characters allowed in two ways:
Directly in the Formula Field's characters (3900). (I think your case)
In the overall size of the Formula after other included Formula
Fields are factored in (5000) bytes.
You can refer this to find workaround Formula Field exceeds maximum number of characters
Hope this Helps !!
Thanks,
Swayam
I have a file with the following structure:
"width" "height" "gray_levels" "pix1" "pix1_length" "pixn" "pixn_length"
Basically, I have to convert this raw data of a raster scanned image back into an image.
Also depending on the amount of gray levels used there will be different character for each gray level. My problem is that I don't really know where to begin. I know that it's better if I have a 2D array, to which I would enter the integer value of different character for the gray level. So i.e. 0 = # (and then I would enter the ASCII value of #)
fscanf(inputfile,"%i %i %i", &x, &y, &gray_levels);
This line reads the dimension of the image for later processing, but I have no idea how to use it without creating a forest i.e. like 10 loops inside one another. I think the main problem is how to program it so that e.g. when first pixel is length 300, I make it to go to the next line in the array.
Also, I shouldn't use malloc because I haven't covered that topic yet. I need to create the size of the array at runtime, so I just created an array with the maximum size of 80*100.
I have a program that creates a table, adds it to a flow document along with table cells that are populated with text. Everything works great with one exception. One column of cells in the table displays costs and they have been formated as follows:
cellValue = "$" + string.Format("{0:##,#.00}", int.Parse(cellValue)).PadLeft(22 -
cellValue.Length);
As it turns out, with this formatting numbers like $ 11,111 take up a different width then numbers like $ 10,000. I would guess because the font is not equal width for each character.
What I would like to do is be able to display the costs just like the are when in an Excel spreadsheet when formatted as Accounting (ie the dollar sign is left hand justified, the numbers are right hand justified and the numbers are lined up from cell to cell).
Example:
$ 10,000.00
$ 11,111.11
If someone knows what formatting to apply to reach this goal please let me know.
This is probably too simple but at a guess I would use fixed font for the cell like "Courier New" so that all the characters are the same width and would align up. The downside of this is that "Courier New" is not the most elegant font to use.
I am sure Excel uses a much more sophisticated mechanism for aligning numeric values.
Maybe you should use something that better mimics a spreadsheet than a table in a flowdocument.
How do I format a field to be
10 characters or numbers
i.e. 112255353v or 5555551155 (for both these conditions)
The field should contain only 10 characters and it can be numbers or letters or both.
Make the field TEXT(10), and set its input mask to AAAAAAAAAA (10 times A).
But that will only affect data entered manually (through tables, queries or forms), NOT anything updated programmatically or using UPDATE or INSERT queries.
To better enforce your rules, you could set the Validation Rule of the field to:
Like "??????????"
or more precisely:
Like "[0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z]"
Use Text Data type. Set Field size to 10.
You should to use the text datatype with a max length of 10.
You could then set the minimum length using an input mask of "AAAAAAAAAA" forcing 10 characters. In input masks "A" or "a" represents either a letter or a digit so you are forcing the user to enter 10 characters of this type.
For a good explanation of what else you could achieve using input masks see http://office.microsoft.com/en-us/access-help/control-data-entry-formats-with-input-masks-HA010096452.aspx