473,386 Members | 1,754 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,386 software developers and data experts.

How to handle Multiple line strings in JavaScript?

Hi

I have stored some vaue that I am getting from textarea to my mysql db like this

"
Some Data,Some More Data
some Extra data
some More Extra data
"

and I am getting that data in JSP page
and I try to access that data in my JSP page using JavaScript

like this
var someValue=
"
"
Some Data,Some More Data
some Extra data
some More Extra data
"

but there is multiple line split problem of string
I try to replace by something like this
someValue.replace("\n","");

and that is not working

any help on this topic
Jul 18 '15 #1
4 3168
Luuk
1,047 Expert 1GB
The might be just linefeeds ("\r") in the text.....

Did you try this too:
Expand|Select|Wrap|Line Numbers
  1. .replace(/\n|\r/,"#")
if this does not help do this to determince which characters are in the text:
Expand|Select|Wrap|Line Numbers
  1. v="Hallo\r\n"
  2. s=""
  3. for (i=0; i<v.length; i++) { s = s + v.charCodeAt(i); }
  4.  
The output of this example should be:
"72971081081111310"
Jul 18 '15 #2
@Luuk

Thanks for replying

Before I can Post first I would like to know If you have to store value of textarea fields in database and preserve all the line breaks that user has typed

and display back that data back in JSP page with JavaScript what will be your approach for this?
Jul 19 '15 #3
Luuk
1,047 Expert 1GB
"JSP page with JavaScript "

JSP = JavaServer Pages

- Java is not equal to JavaScript
- I do not have (enough) knowledge about JSP
- I would display it so the it will look the same ;)
Jul 19 '15 #4
Sherin
77 64KB
Try This Code
Expand|Select|Wrap|Line Numbers
  1. <!doctype html>
  2.     <head>
  3.         <title>Multi-line JavaScript Strings</title>
  4.     </head>
  5.     <body>
  6.         <div id="var1"></div>
  7.         <div id="var2"></div>
  8.         <div id="var3"></div>
  9.  
  10.         <script>
  11.             /* JS comes here */
  12.             var myStr1 = `This is my
  13.                 multiline String
  14.                 which is amazing`;
  15.             // adding string value to HTML tag 
  16.             document.getElementById('var1').innerHTML = myStr1;
  17.  
  18.             var myStr2 = "This is my                 multiline String                 using backslash to escape new line";
  19.             // adding string value to HTML tag 
  20.             document.getElementById('var2').innerHTML = myStr2;
  21.  
  22.             var myStr3 = "This is my" +
  23.                 " multiline String " +
  24.                 " using concatenation technique";
  25.             // adding string value to HTML tag 
  26.             document.getElementById('var3').innerHTML = myStr3;
  27.  
  28.         </script>
  29.     </body>
  30. </html>
OUTPUT

Expand|Select|Wrap|Line Numbers
  1. This is my multiline String which is amazing
  2. This is my multiline String using backslash to escape new line
  3. This is my multiline String using concatenation technique
  4.  
Jun 17 '20 #5

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

Similar topics

8
by: MrTrix | last post by:
Hello: I'm having a problem formulating the code to execute a multiple line command. I'm trying to execute something like: set rowcount 100000 declare @rowct int select @rowct = 1 while...
7
by: AboutJAV | last post by:
Hi, I was thinking of using MSMQ to handling multiple simultaneous database request to update or insert records to table. There could be hundreds of database existing connections trying to...
6
by: skyy | last post by:
Hi.. i would like to know how to handle multiple upload files with the cgi module in perl script.. With single file, my $my_cgi new CGI; my $upload_filehandle = cgi ->upload('file1'); my...
1
by: pvrsatya | last post by:
Hi Need a example for TCP server program in C or c++ to handle multiple clients
2
by: apollo135 | last post by:
Dear All, Could someone help and tell me how to handle multiple send and receive operations with udp sockets? In fact here is my problem: server.c is composing of serveral sub programs (the...
1
by: stewc | last post by:
Hi I am using this line of code var str = (<r><!]></r>).toString(); to convert a multiple line string to a single line so I can remove the line breaks It works great in Firefox but...
0
by: tochisan | last post by:
Hello all, I'm writing a c# console program that's going to be run as a service but I want it to have the ability to handle arguments and run in a certain way. The program is supposed to monitor...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
4
by: fjm | last post by:
Hello everyone. I’d like to know how to handle multiple style sheets. I have css tabs that have a style sheet and then I also have a separate style sheet for the content that goes inside the tab. ...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.