displaying text from InnerText - asp.net

When I try and display text from an the InnerText from an XML element. I get something like this:
I need this spacing \r\n\r\n\r\second lot of spacing\r\n\r\nMore spacing\r\n\r\n
I know you can replace \r\n with <br> but is there no function that automatically takes the html for you and why does it use \r and \n? Many thanks.

You can use <pre> tag - it will show the text as-is like you see it in text editor:
For example:
<pre><%=MyText%></pre>
Better practice for ASP.NET is:
<pre id="myPlaceholder" runat="server"></pre>
Then assign its value from code behind:
myPlaceholder.InnerHtml = MyText;
As for your question "why does it use \r and \n" those are carriage return and line feed characters, aka newline characters - when you have such text:
line 1
line 2
Then code reading it will give: line1\nline2 or line1\r\nline2 depending on how it's stored exactly.

Related

Scrapy - Remove comma and whitespace from getall() results

would there be an effective way to directly remove commas from the yielded results via getall()?
As an example, the data I'm trying to retrieve is in this format:
<div>
Text 1
<br>
Text 2
<br>
Text 3
</div>
My current selector for this is:
response.xpath("//div//text()").getall()
Which does get the correct data but they come out as:
Text 1,
Text 2,
Text 3
instead of
Text 1
Text 2
Text 3
I understand that they get recognized as a list which is the reason for the commas but would there be a direct function to remove them without affecting the commas from the text itself?
I'm just going to leave the solution I used in case someone needs it:
tc = response.xpath("//div//text()").getall() #xpath selector
tcl = "".join(tc) #used to convert the list into a string

paste0 regular and italicized text in R

I need to concatenate two strings within an R object: one is just regular text; the other is italicized. So, I tried a lot of combinations, e.g.
paste0(" This is Regular", italic( This is Italics))
The desired result should be:
This is Regular This is Italics
Any ideia on how to do it?
Thanks!
In plot labels, you can use expressions, see mathematical annotation :
plot(1,xlab=expression("This is regular"~italic("this is italic")))
To provide an string for which an HTML parser will recognise the need to render the text in Italics, wrap the text in <i> and </i>. For example: "This is plain text, but <i>this is in Italics</i>.".
However, most HTML processors will assume that you want your text to appear as-is and will escape their input by default. This means that the special meanings of certain characters - including < and > will be "turned off". You need to tell the processor not to do this. How you do that will depend on context. I can't tell you that because you haven't given me context.
Are you for example, writing to a raw HTML file? (You need do nothing.) Are you writing to a Markdown file? If so, how? In plain text or in a rendered chunk? Are you writing a caption to a graphic? (Waldi has suggested a solution.) Etc, etc....

How to make a link of a substring in reStructuredText (RST)

How can I make a link inside a string in RST?
Like so:
ImInTheMiddelOfAString - without adding spaces between The and Middle and Middle and Of.
But in reStructuredText (RST).
If I simply write the rst like so:
ImInThe`Middel <http://foo.com>`_OfAString
I get this as the result (so no link):
ImInThe`Middel <http://foo.com>`_OfAString
If I write this:
ImInThe `Middel <http://foo.com>`_OfAString
I get an error, and finally if I write this:
ImInThe `Middel <http://foo.com>`_ OfAString
I get the link but with spaces in between:
ImInThe Middel OfAString
I found out that I can use backslash to escape the space.
So this:
ImInThe\ `Middel <http://foo.com>`_\ OfAString
Gives me the right result:
ImInTheMiddelOfAString

How to avoid implicit mailto link in Restructured Text?

I'm new to Restructured Text and am trying to write a document that refers to a project with an "at" sign in the name, something like "Foo#BAR". When I convert the .rst file into HTML using the docutils "rst2html" tool, this is converted into a "mailto" link. If I use double backticks for verbatim rendering, it is turned into monospace text. How can I get it to be rendered in the normal text font, and not converted into a link?
You can use character escaping to include an # within a word. In reStructuredText the escape character is \, so try using Foo\#BAR in your document.

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