473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

escaping or encoding line break

Claus Mygind
571 512MB
The following line causes a "unterminated string literal" error when the string from a LONGTXT field contains a hard return (paragraph marker, whatever).

Expand|Select|Wrap|Line Numbers
  1. eval("var result = " + string)
How can I escape and still preserve the hard return?
May 2 '08 #1
5 7805
Claus Mygind
571 512MB
The following line causes a "unterminated string literal" error when the string from a LONGTXT field contains a hard return (paragraph marker, whatever).

eval("var result = " + string)

How can I escape and still preserve the hard return?


I see that I need to use the replace( ) method

ie:

Expand|Select|Wrap|Line Numbers
  1. newString = string.replace( ??, "\n")
I just don't know how to identify the hard return in the string.
May 2 '08 #2
gits
5,390 Expert Mod 4TB
try this:

Expand|Select|Wrap|Line Numbers
  1. var newString = string.replace(/(\r)/g, '\n')
\r is a carriage return ...

kind regards
May 3 '08 #3
Claus Mygind
571 512MB
Thanks for the reply. My problem is this. How do Identify the line break. It is not a visible character? I want to replace the line break with the escaped character. Or perhaps I need to identify both the "carriage return" and the "line break" and replace them with "\r\n"
May 3 '08 #4
Claus Mygind
571 512MB
Ok I think I may have figured it out

//this line replace the escaped line feed with a carriage return
var yData = xData.replace( /%A/g, "\r").

But I am not sure if that is how identify the hidden carriage return
May 3 '08 #5
gits
5,390 Expert Mod 4TB
hmmm ... i think the following replace should work, when you want to replace the linebreak with a carriage return:

Expand|Select|Wrap|Line Numbers
  1. var yData = xData.replace(/(\n|\r\n)/g, '\r');
kind regards
May 5 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Roland Dalmulder | last post by:
Hello all, In my PHP script I put a text file into a string. Part of that string is read, changed and removed. The while loop continuest to extract the next part of the string. This goes all...
5
by: Wai Yip Tung | last post by:
When I do for line in fp: the line string usually has a '\n' at the end. In many cases I don't want the line break character. I can trim it using if line.endswith('\n'): line = line ...
5
by: Kathryn | last post by:
Good morning! I am having a problem with a span. I have items, of which I only want to show the first X characters on the screen. If the user prints the page, I want the entire item to print....
6
by: Nurchi BECHED | last post by:
Hello, All! I have created an application with a multiline textbox on the form. When I press a button, it has to show something and then break the line and show something else. I tried "\n",...
1
by: questionz_99 | last post by:
How would I specify line breaks of specific height? For example, if I wanted to insert a 6-point line break, what would the CSS code look like? Obviously, I'd like something more specific than...
3
by: lmawler | last post by:
Hi all, I know when I do data entry, I can force a line break in a text box by using Control & Enter. I'm trying to insert a line break in a field (that behaves like Control Enter) from VB. ...
4
by: deerchao | last post by:
Hi, I'd like to render colorful text with word wrap on screen (kind of inline <fonttag to change text color in html), but run into the line break problem. Graphics provides several DrawString...
1
by: mccalla | last post by:
Hi all, Tricky question. I know how to remove line break characters and spaces by using the code below: $message =~ s/\n//g; $message =~ s/\s//g;
7
by: jeddiki | last post by:
Hi, I am using a function called htmlwrap() which states that it does NOT add a "<br>" to the 70 character line so that it forces a line wrap. ( the script safely wraps long words without...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.