Write a program for word-wrap - size

Write a program for word-wrap which should work on any screen size?
Given a sequence of words, and a limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line width.
The word processors like MS Word do task of placing line breaks. The idea is to have balanced lines. In other words, not have few lines with lots of extra spaces and some lines with small amount of extra spaces.

Related

Markdown Paragraph

I'm encountering a problem in Markdown paragraph.
I use Notepad in Microsoft Windows to create .md file and use Typora for rendering.
The new lines in the same paragraph are treated as new line in rendering.
For example, if my .md file contains the following text
Electric Field inside
a conductor
is zero
The Typora renders as it is with new lines....whereas it is expected the rendering should be like this
Electric Field inside a conductor is zero.
i.e new lines inside the same paragraph to be formatted in proper paragraph sense and not like code listing. Whats the mistake I' doing ?.
Typora seems to not follow typical Markdown behavior in this regard. As explained in their documentation:
A paragraph is simply one or more consecutive lines of text. In
markdown source code, paragraphs are separated by two or more blank
lines. In Typora, you only need one blank line (press Return once)
to create a new paragraph.
Press Shift + Return to create a single line break. Most other
markdown parsers will ignore single line breaks, so in order to make
other markdown parsers recognize your line break, you can leave two
spaces at the end of the line, or insert <br/>.

Streamwriter adding unwanted characters to the beginning of the line

I've written a program to write out an automated, delimited invoice file, and it seems to work properly, the file looks correct in notepad. However, when the file is received on the other end, there are a couple of extra characters at the beginning.
The code is basically
fWriter = My.Computer.FileSystem.OpenTextFileWriter(OutputPath)
LineString = 'insert line here
fWriter.WriteLine(LineString)`
the screenshot from the client has a three odd shaped characters at the beginning. They aren't in the input string, and I'm lead to believe it's because the OpenTextFileWriter isn't writing ascii, but it's a flat text file, or it's supposed to be.
Any help would be appreciated.

Word VBA search for adjacent (non-space) characters with different formatting

I need to be able to find every place in my document (hundreds of pages) where there is a formatting change without a space. For example:
a bold partnext to regular text
Or red text next to black with no space. I want to have my macro find each "word" (in the vba sense) like this, and execute code based on that character location accordingly. (The loop should identify the character position where the format change occurs... although I can do that part with a loop through the characters within the found word).
Is there a simpler way to do this than by looping character by character through the whole document and checking for a difference in formatting, which would be too resource-intensive?
Thanks for your help.

Word 2013: Suppress Line Numbers VBA

I am stuck.
At my organization, we need to check if line numbers are active for a given paragraph. We are attempting to do this but are running into an issue with suppressed line numbers.
We have tried:
Selection.Information(wdFirstCharacterLineNumber)
and
Paragraph.Range.PageSetup.LineNumbers.Active = True
However, the paragraph(s) we are trying to avoid have suppressed line numbers. We are trying to determine whether or not the current paragraph has line numbers.
If line numbers are suppressed LineNumbers.Active returns True for the current paragraph. In addition, if line numbers are suppressed then wdFirstCharacterLineNumber returns 1 for the first paragraph even though it is obviously not 1 as I see 1 in a lower paragraph.
I have not found a function that returns a bool or an integer if line numbers are suppressed for a given paragraph.
I welcome any suggestions. Thank you.
Line numbers are valid for the entire document, which is why what you've tried is returning the information it is.
Line number suppression is direct formatting applied to individual paragraphs, so you need to query the paragraph properties. For example:
If Selection.Paragraphs(1).NoLineNumber Then
'True (-1) means the line numbers are suppressed
Else
'Flase (0) means the line numbers are visible
End If

C Programming Format Adjustment

I am asking for some homework help. I am not asking for the answer,I just wanted to be pointed in the right direction.
I have a program in C which I am new to. I have to recreate a Unix tool using vi. Its job will be to read input and “neaten” it up. It reads in paragraphs of words and rearranges them such that they fit nicely onto a line of specified width, inserting line breaks as needed. A paragraph is separated from other paragraphs by one or more empty lines than changing the width with -w and changing to right alignment using -r.
Next would be to justify the text using -j so that every line with more than one word extends from the left to the right with max width. I need to apply integer division to calculate the total number of spaces that should have been seen by the time you finish a gap using Kevin Woods Si = i*S/G where S is the total number of spaces needed in the line, G is the number of gaps between words in the line and Si is the number of spaces that should have appeared by the end of the i'th gap. Lastly suppress line spacing from lines entered with more than a double line back into a double line.
The options should be cumulative—I can specify width, alignment, and skipping of blank lines together. The -r and -j flags should not be used together.
first step: metacode
main(arguments)
analyse arguments f.e. with getopt() for correctness and validity
read the original text
break the text into virtual paragraphs (identified by a double LineBreak)
for each paragraph
break it into lines of less than allowed (-w, default 80) characters
for each line that is not the last line of a paragraph
fill with spaces according to your algorithm and command line spezification
print out all lines
second step: coding
this is your task. Please come back, when you have code, that shows us, where you are stuck.