Solved

formatting multiline string

Posted on 2003-11-06
7
409 Views
Last Modified: 2008-03-04
Say I have the following string:

This is a
multi-line string
that should
be one line.

How do I get it to one line?

I've tried replace(string, CHR10, "\n") and replace(string, CHR13, "\n") and replace(string, vbcrLf, "\n") to no avail.

This text is coming from an Err.Description and going to be put into a session variable and then displayed in javascript on the next page.

Thanx in advance
B.D.
0
Comment
Question by:Big Monty
7 Comments
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 9697521
try this

replace(string, vbcrLf, "")

in your code you are replacing the LINE BREAK with the LINE BREAK(\n). try using a empty String.
0
 
LVL 12

Expert Comment

by:kingsfan76
ID: 9697525
I think "\n" is a new line character for javascript.
try to replace it with an empty space "" and see if it works
0
 
LVL 33

Author Comment

by:Big Monty
ID: 9697624
i want it to be a new line break because if i don't, then it shows up in javascript like:

alert("this is the error message
that i got from err.description. you see how
it keeps going like this?")

as you can tell this is not a valid javascript alert message. my theory was that if i translated the line breaks into \n, then i would reserve the format
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 3

Accepted Solution

by:
monvelasquez earned 125 total points
ID: 9699125
i think you need something like...

--[CODE]--------------------------------------------------------
Replace(asp_string_var, vbCrLf, "\n")
--[/CODE]--------------------------------------------------------

to use this in javascript use it like this..

--[CODE]--------------------------------------------------------
<script language="javascript">

alert("<%=Replace(asp_string_var, vbCrLf, "\n")%>");

</script>
--[/CODE]--------------------------------------------------------

However you still need to take care of quotes...

so you need..

--[CODE]--------------------------------------------------------
<%
jscript_string = Replace(asp_string_var, vbCrLf, "\n")
jscript_string = Replace(jscript_string, """", "\""")
%>
...some code here....
<script language="javascript">

alert("<%=jscript_string%>");

</script>
--[/CODE]-------------------------------------------------------



hope this helps..

____________
Raymond:\>_
0
 
LVL 15

Expert Comment

by:deighc
ID: 9702378
I'm surprised that

replace(string, vbcrLf, "\n")

doesn't work. Perhaps you should try

replace(string, vbLf, "\n")

instead. May the text lines output from the error object are seperated only be a line feed (vbLf) rather than a carriage return line feed (vbCrLf).
0
 
LVL 28

Expert Comment

by:sybe
ID: 9703619
Replace(string, CHR(13) & CHR10, "\n")
0
 
LVL 33

Author Comment

by:Big Monty
ID: 10561766
forgot i left this open so i decided to clean up now
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question