0

My text from DB is like

title &vbCr& "1. conetnt01" &vbCr& "  1.1 sub" &vbCr& "2. content02" &vbCr& "  2.2 sub"

After replaced vbCr to vbCrLf

In docx

title 
1. conetnt01
1.1 sub content
2. content02
2.2 sub

But my expect is

1. conetnt01
  1.1 sub content
2. content02
  2.2 sub

What can I do for this situation?

Finally my solution is below, but the empty in the first line is disappeared.

str = str.Replace("  ", " ")
str = str.Replace(vbLf, vbCrLf)
Kidd Wang
  • 13
  • 3
  • A) You would need to parse the text to work out where the title, sections and subsections are. I do not know for sure, but it appears to me that then, using the [Paragraph Interface](https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.interop.word.paragraph?view=word-pia), you would set the appropriate styles for each paragraph. B) Perhaps you could store the text in the DB in a different format, perhaps RTF or HTML, which would allow you to parse the text more easily and without errors. – Andrew Morton Dec 31 '19 at 13:07
  • Oops, I missed the Novacode tag. Unfortunately Firefox tells me there is something dodgy about their website at the moment, so I am unable to look at it. Perhaps you could edit your question to show the part of the code that produces the result you show. – Andrew Morton Dec 31 '19 at 13:14
  • Would vbTab help? – Mary Dec 31 '19 at 14:24
  • How did you replace vbCr with vbCrLf? Can you show your code? Have you tried `Environment.NewLine`? – preciousbetine Jan 01 '20 at 06:35

1 Answers1

0

[vbCr] return to line beginning: Represents a carriage-return character for print and display functions.

[vbCrLf] similar to pressing Enter: Represents a carriage-return character combined with a linefeed character for print and display functions.

[vbLf] go to next line: Represents a linefeed character for print and display functions.


"keep calm and start coding!"

  • In the olden days of manual typewriters, when you came to the end of a line you would hit the lever. The entire carriage would move to the right to where the start of line was.(The Cr) Also, the platen (the cylinder where the paper rested) would advance the paper one line. (The Lf) I learned to type on a manual typewriter. – Mary Dec 31 '19 at 14:33
  • 4
    This doesn't answer the question. – Blackwood Dec 31 '19 at 16:04