HI, using C# I am saving formated HTML data in MSSQL such as:
I am than populating it into a textarea to display. I understand that I can use the .val() method in jQuery to pull all of the ASCII characters out of the textarea, however, I can't seem to figure out how to get the "\n" and "\t" characters to show up as new lines and tabs.
When I use FireBug to check the html contents of the textarea in question, this is what is displayed:
<div>/\n/\t<p>This is a test Div</p>/\n</div>
I don't really care about using jQuery to display the new lines and tabs, I can also use .NET to change the characters, I would just like to know either or both options.
In .NET you can use String.Replace:
s = s.Replace(@"\n", "\n"); s = s.Replace(@"\t", "\t");
You might want to consider whether you should make this replacement before you insert the data into the database rather than as you fetch it, because you'll probably only be inserting it once but fetching it a lot of times.
You should be saving your data better than that... but for now, you can use a simple regex trick:
yourString.replace(/\\n/g, "\n").replace(/\\t/g, "\t");