Solved

formatting multiline string

Posted on 2003-11-06
7
407 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:adilkhan
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 32

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 32

Author Comment

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual Project Bridge error 5 56
ASP equivalent to Windows findstr 3 59
JQuery Date Time picker not showing 29 92
Copy only dates 3 70
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 demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now