In OpenTBS: How to use "new paragraph" carriage returns instead of "new line" in MS Word Templates - docx

I have a PHP variable holding plain text that i need to insert into a MS Word Template using OpenTBS.
My Word placeholder is:
[onshow.introduction]
The problem is I use justification formatting, so I need actual "new paragraph" ie "carriage returns" (Enter) in Word. Instead all my newlines are translated into "new line" (shift-Enter), messing up my formatting.
I tried inserting , \r, \n, \n\r, \r\n, PHP_EOL - all of them just create newline characters instead of new paragraph characters in MS Word.
Is there any way to get "new paragraph" characters in Word from OpenTBS?

In Ms Word, a new paragraph is a complicated XML entity. Something like:
<w:p><w:r><w:t>My paragraph</w:t></w:r></w:p>
and it can have extra attributes and extra sub-entities that can appear at several places.
So it would be very touchy and hazardous to replace your line-breaks with </w:t></w:r><w:r><w:t>.
The best and robust solution is to explode your text in several parts, and merge it on a block bounded an Ms Word paragraph.
Example :
PHP:
// uniformize line breaks
$introduction = str_replace("\n", "\r", $introduction);
$introduction = str_replace("\r\r", "\r", $introduction);
// explode in several parts
$introduction = explode("\r", $introduction);
// merge on a block
$TBS->MergeBlock('intro', $introduction);
DOCX:
[intro.val;block=tbs:p]

Related

How to remove characters between space and specific character in R

I have a question similar to this one but instead of having two specific characters to look between, I want to get the text between a space and a specific character. In my example, I have this string:
myString <- "This is my string I scraped from the web. I want to remove all instances of a picture. picture-file.jpg. The text continues here. picture-file2.jpg"
but if I were to do something like this: str_remove_all(myString, " .*jpg) I end up with
[1] "This"
I know that what's happening is R is finding the first instance of a space and removing everything between that space and ".jpg" but I want it to be the first space immediately before ".jpg". My final result I hope for looks like this:
[1] "This is my string I scraped from the web. I want to remove all instances of a picture. the text continues here.
NOTE: I know that a solution may arise which does what I want, but ends up putting two periods next to each other. I do not mind a solution like that because later in my analysis I am removing punctuation.
You can use
str_remove_all(myString, "\\S*\\.jpg")
Or, if you also want to remove optional whitespace before the "word":
str_remove_all(myString, "\\s*\\S*\\.jpg")
Details:
\s* - zero or more whitespaces
\S* - zero or more non-whitespaces
\.jpg - .jpg substring.
To make it case insensitive, add (?i) at the pattern part: "(?i)\\s*\\S*\\.jpg".
If you need to make sure there is no word char after jpg, add a word boundary: "(?i)\\s*\\S*\\.jpg\\b"

How to delete only (anyword).com in Regex?

I'd like to match the following
My best email gmail.com
email com
email.com
to become
My best email
email com
*nothing*
Specifically, I'm using Regex for R, so I know there are different rules for escaping certain characters. I'm very new to Regex, but so far I have
\ .*(com)
which makes the same input
My
But this code does not work for instances where there are no spaces like the third example, and removes everything past the first space of a line if the line has a ".com"
Use the following solution:
x <- c("My best email gmail.com","email com", "email.com", "smail.com text here")
trimws(gsub("\\S+\\.com\\b", "", x))
## => [1] "My best email" "email com" "" "text here"
See the R demo.
The \\S+\\.com\\b pattern matches 1+ non-whitespace chars followed by a literal .com followed by the word boundary.
The trimws function will trim all the resulting strings (as, e.g. with "smail.com text here", when a space will remain after smail.com removal).
Note that TRE regex engine does not support shorthand character classes inside bracket expressions.

Determining delimeter for a structured section in a text file using a hex viewer

I have a text file with structured data. After each text block it says "END" and continues onto the next block. Looking at a hex viewer I see
0A:45:4E:44:0A:20:20:20:20:20:20:20:20:20
which translates into
?END?
Notice the 9 spaces.
How do I write this as a delimeter in my code?
"END\n\n\n \n \n \n \n \n \n"
This doesn't seem to work. What am I missing?
Most likely,
"\nEND\n "
however you forgot to mention which language you're using. Where did up get all those extra \ns from?

ASP.NET - How do you escape an apostrophe with a slash to insert in a database

I am not sure how to escape an apostrophe with a slash. I am using fckeditor and fckeditor replaces all single apostrophes with double apostrophes. My code is doing the same thing so when I view the content there are two apostrophe in the html. I thought that I could escape the apostrophe with a slash and that should do the trick.
According to this list of HTML entities you should use &apos; (but this will apparantly not work in IE) or '.
You can find more on the HTML Symbol Entities Reference.
You should replace double quote with
This code 9" x 9" with give you output as 9" X 9"
And if your database row contain single apostrophe, you can display by assigning that value to lable controls text property and it should work without any issues.
You should replace with
"
which is the best and sometimes only way to store quotaiton marks in text fragments.

No Line Breaks with Text file with asp.net

I want to read a text file and load its content to my page. I was trying to read the file with StreamReader and then assign the text to a Label, but the text in the page is just one line. I mean the line in the text file wasn't viewed in the page. What should I do?
Perhaps tackling a symptom rather than the problem itself, you can wrap the text file's contents within a <PRE> tag wherein, unlike most other content in HTML, whitespace is respected.
The textfile uses \n or \r\n for getting new lines (\n is a newline and \r is a carriage return - back in the day of typewritters you had to pull the bar thingy back to the left which is called a carriage return and roll the paper down a line to start on the left side of a newline-). Windows generally uses \r\n (although it depends on the application that created the file) mac's generally use \n.
HTML on the other hand uses the <br/> tag for new lines (if you do a viewsource on your current html output you will see the newlines). So all you need to do is replace \r\n or with . You can do this with:
yourstring = yourstring.Replace("\r\n", "<br/>");
or if you don't know for sure what's used in the file or both \r\n and \n are used you can use
yourstring = yourstring.Replace("\r\n", "<br/>").Replace("\n", "<br/>");
be aware that a string is immutable and thus methods like Replace return a copy of the string that has the replacements made. The original string will stay intact.
Please try this
if (System.IO.File.Exists(Server.MapPath("test.txt")))
{
System.IO.StreamReader StreamReader1 = new
System.IO.StreamReader(Server.MapPath("test.txt"));
lblMyLabel.Text= StreamReader1.ReadToEnd();
StreamReader1.Close();
}
HTML doesn't recognize white-space (line breaks, etc) in your text file. If you want to render the content as HTML, you'll need to convert line-breaks into <br/> tags.
Try something like this:
string path = 'c:\myfile.txt':
lblMyLabel.Text = String.Join('<br/>', File.ReadAllLines(path));

Resources