I hope, there is a solving of my question. But I can't find it.
Problem: ajax return data with line break (\n). The data must be insert into textarea and will be update from ajax.
I can replace '\n' when reading data (myJsonData.replace.() ... etc). The main problem: how to ready data for textarea to display in correct format with line break?
just replace it to something revertable, like -=br=- and when insert to the textarea, replace back to \n
There is no problem with line breaks in textarea and you just can insert the data as is. But if you still have problems with special chars - you can encode your JSON data and decode it on insert.
Related
I'm trying to store text in my database with \n, so that there can be new lines whenever the admin wants. The problem I am getting is that automatically it seems laravel is sanitizing all strings that get saved to the DB. So it's saving it as \n. And then when I retrieve it (i retrieve and display with vue components not a blade file), it doesn't format it as a new line. how and what am i supposed to do. what is the right way of achieving being able to save a paragraph with new lines made with \n?
I think you need to convert the \n to be. you can do something like this:
<?php
echo nl2br("foo isn't\n bar");
?>
i am required to simulate a carriage return (0A) to save into the database from a web application so that i can prove that the system is not cleaning data causing some issues, this needs to be entered in the browser as a plain text, are we able to do this?
I don't know what you are trying to achieve, but here's an article that uses CHAR() function in SQL query http://msdn.microsoft.com/en-us/library/ms187323.aspx
insert into mytable(mytext) values('Dear Sir:' + CHAR(13)+CHAR(10) + 'This is')
Line feed char(10)
Carriage return char(13)
Line feed char(10) is correct
Carriage return char(13) is giving issues.
From this question: What character represents a new line in a text area
By HTML specifications, browsers are required to canonicalize line
breaks in user input to CR LF (\r\n).
Hence, you can't insert any other style of newline through a browser.
I've searched online and on StackOverflow, but I can't seem to find the answer to my question, although some of them came very close.
I am programming for .Net in Delphi Prism. I have a RichTextBox on a WinForm and I need to insert a line of text at the top every time program does insert. So, I am doing the following and it runs upto the line and raises the following exception.
offending code:
RichTextBox1.Lines.SetValue(str,0);
Exception:
Index was outside the bounds of the array
I think, I think I know why it is raising the exception. It's because there are no lines inserted into RichTextBox. So, my program really can't insert any line of text. I need to really insert line of text at the top everytime my program inserts a new line of text.
If I do call RichTextBox1.AppendText(str);, then it works and inserts the str text without newline, but it appends at the end. I want it inserting text at the top every time.
How do you insert line of text into RichTextBox?
Thanks.
The Lines property of the textbox is simply an array of string. So you need to add one element, move all elements one index down and insert your new text at the first index.
Also the Text property of the textbox is a string. Strings in .NET are immutable, so you need to fully replace the value.
One approach would be like this:
RichTextBox1.Text := "YourNewText" + Environment.NewLine + RichTextBox1.Text;
I've got an internationalised app that uses spring and freemarker. I'm getting content from localised property files using.
${rc.getMessage("help.headings.frequently_asked_questions")}
For some of the content there are carriage returns in the property values. Because I'm displaying in a web page I'd like to replace these with .
What is the best way to do this?
Edit: looking closer it seems that I don't actually have carriage returns in the property files. The properties are coming back as single line strings.
Is there a better way to declare the properties so they know they are multi-line?
help.faq.answer.new_users=If you have not yet set a PIN, please enter your username and passcode (from your token) in the boxes provided and leave the PIN field blank.\
You will be taken through the steps to create a PIN the first time you log in.
Cheers,
Pete
${springMacroRequestContext.getMessage("help.headings.frequently_asked_questions", [], "", false)?html?replace("\n", "<br>")}
To handle CR + LF (carriage return + line feed) line endings, as well as just LF do this:
<#escape x as x?html?replace("\\r?\\n","<br />",'r')>...</#escape>
<#escape x as x?html?replace('\n', '<br>')>...</#escape>
works just fine.
If you want this to be the default behaviour, consider writing a custom TemplateLoader as suggested in this blog: http://watchitlater.com/blog/2011/10/default-html-escape-using-freemarker/.
As to the
Is there a better way to declare the properties so they know they are multi-line?
part of your question, maybe this helps: you can include line terminator characters in your property values by using the \r and \n escape sequences, like it is explained in the API documentation of java.util.Properties#load(java.io.Reader).
I would recommend writing a custom directive for it (see freemarker.template.TemplateDirectiveModel), so in your templates you can write something like <#my.textAsHtml springMacroRequestContext.getMessage(...) />. It's important that this is a directive, not function, so it works properly inside <#escape x as x?html>...</#escape>. Otherwise it would be double-escaped. Using a directive can also give the highest performance, as you can directly send the output to the output Writer, rather than building a String first.
I have a question about htmlagilitypack.
How can I insert into specific line or lineposition (not node)? If I have HtmlParseError at line 100 (missing opening tag ), how can I insert this missing tag into that line.
In the general case, you can't.
You'll have to reload the file with a standard text stream (StreamReader say), and fix it directly in the raw text, using the line & column position.