We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

# how to append new line character in string variable

on
Medium Priority
377 Views
Hi Experts
I have the following code:

If read.IndexOf("<tr bgcolor=" & Chr(34) & "#FFFFFF" & Chr(34) & ">") <> -1 Then 'find the cheapest price in this page

Do
cheapStr &= read & Chr(13) & Chr(10)
End If

If read.IndexOf("\$") <> -1 Then 'Get the price
For i As Integer = 0 To 1
Next

If Double.Parse(cheapPrice) < cheapestprice Then
cheapestprice = Double.Parse(cheapPrice) 'Cheapest Price here
renew = True

If renew Then
cheapeststr = cheapStr.Substring(cheapStr.LastIndexOf("<tr bgcolor=" & Chr(34) & "#FFFFFF" & Chr(34) & ">"))
End If
End If

End If

cheapStr &= Chr(13) & Chr(10)

End If

End While
strm.Close()
webRes.Close()

Loop While departuredate <= enddate

Response.Write(cheapStr)
Response.Write("<b>")
Response.Write("The cheapest price is: " & cheapestprice)
Response.Write(cheapeststr)
Response.Write("</b>")

The above code prints the 'sheapStr' string value in one line. I want to separate each line. For example
cheapStr &= Chr(13) & Chr(10)
the above line should print the string value in separate line as i append chr(13) & chr(10) to make new line in string.

i tried alot by using the following:
cheapStr &= Environment.NewLine()
cheapStr &=  ChrW(13) + ChrW(10)
cheapStr &= ControlChars.Crlf
cheapStr &= ControlChars.NewLine
Doesn't make any differene.
Let me make one thing more clear for you. The string variable cheapStr is taking value as html string. I didn't try to append html way of separating lines. Any suggesstions.......?
Comment
Watch Question

## View Solutions Only

Commented:
di you try

cheapStr &=  "<br />"

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:
Dean is right here...  writing vbCrLf to HTML will not mean anything to the browser's rendering engine.  Everywhere you want the line to break in the HTML display you need "<br>".

John
CERTIFIED EXPERT

Commented:
try

cheapStr = cheapStr & Chr(13) & Chr(10)

or

cheapStr = cheapStr & "<br>"

Commented:
Hi guys i tried </ br> and it works fine. I need little more help from you guys if u dont mind.

I have several of these lines of code in my aspx page "View Source":

<form action="input-verifforf.cgi" method=post>
<input type=hidden name=sid value="c319599a55230c2a9a10778b6cb9192b">
<input type=hidden name=result value="dc5315d5950b5e6f9d10fa3879b94c4">
<input type=hidden name=language value="">
<td align=left bgcolor="ffffff"><span class="style2">CANCUN</span></td>
<td align=left bgcolor="ffffff"><span class="style2">
<a href="javascript:popWinS('http://webstar.softvoyage.com/cgi-bin/hotel_desc.cgi?sun&&http://webstar.softvoyage.com/hotels/VACen/AKUMCUN.html',600,600,'1')"><nobr>AKUMAL BEACH RESORT</nobr></a></span></td>
<td align=center bgcolor="ffffff"><span class="style2">3</span></td>
<td align=center bgcolor="ffffff"><span class="style2">STD-GARD</span></td>
<td align=center bgcolor="ffffff"><span class="style2">AI</span></td>
<td align=center bgcolor="ffffff"><span class="style2">NOV-15-2006</span></td>
<td align=center bgcolor="ffffff"><span class="style2">7</span></td>
<td align=center bgcolor="ffffff"><span class="style2">\$967.00</span></td>
</br>

What im trying to do is to take out http://.. link , resort name which is AKUMAL BEACH RESORT, 3(Star Rating), STD-GARD, AI, NOV-15-2006, 7, \$967.00 from all the occurance of these lines of code. I'd it pretty much but didn't get the exact way of how to show the result in display.Below is my code:

webReq = WebRequest.Create(newurl)
webRes = webReq.GetResponse()
strm = webRes.GetResponseStream()
renew = False

If read.IndexOf("<form action=") <> -1 Then
strBuild = "<div><a id=Hyperlink1 href=" & read & ">" & strResort & "</ a></div>"
Response.Write(strBuild)
strBuild &= "<div>" & read & "</div>"   'Star Rate
MsgBox(strBuild)
strBuild = Nothing
End If
End While

strm.Close()
webRes.Close()
I want the result to show up on display like that:

Hotel: AKUMAL BEACH RESORT
Star:  3
Meal: AI
Date: NOV-15-2006
Duration: 7
Price: \$967.00

I wana clearify that there are multiple occurance of these hotels etc... thats y i traverse it till </html>
CERTIFIED EXPERT

Commented:
what result does your code produces now?

Commented:
it just produces 4 hyperlinks of AKUMAL BEACH RESORT which is perfect but it should also append 4 times star rating 1 for each hotel but its not displaying anything which is not good :(

any help plz
CERTIFIED EXPERT

Commented:
try replacing this line
with

Commented:
doesn't make any difference
CERTIFIED EXPERT

Commented:

or

Commented:
my working code generates the below view source:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
Untitled Page
<body>
<form name="form1" method="post" action="Backnew.aspx?code_ag=sun&amp;alias=sun&amp;gateway_dep=YYZ&amp;dest_dep=CUN&amp;duration=7&amp;departure_month=11&amp;departure_day=16&amp;departure_day_to=30&amp;departure_month_to=11&amp;no_hotel=1346&amp;star=3&amp;flex=Y&amp;price_max=99999&amp;searchtype=FO" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTUxMzcyMjQyN2RkY7KD7tf88gE+uOMtbRrLaAa0jpE=" />
</div>

<div>
<br />
&nbsp;

</form>
</body>
</html>
CERTIFIED EXPERT

Commented:
did you try debugging to make sure

gets the correct line?

Commented:
well i did and its giviing me the exact code which i want to display on the page:

the above line will give me '3' which is what i want in read variable. The problem is in displaying it on the page. How can i append the 'read' variable with strBuild variable to display it with previous strBuild value
CERTIFIED EXPERT

Commented:
try changing this line
strBuild &= "<div>" & read & "</div>"   'Star Rate

to

strBuild =StrBuild & "<div><b>" & read & "</b></div>"   'Star Rate

CERTIFIED EXPERT
Commented:
actually change

strBuild &= "<div>" & read & "</div>"   'Star Rate
MsgBox(strBuild)

to

strBuild &= "<div>" & read & "</div>"   'Star Rate
Response.write(strBuild)
CERTIFIED EXPERT

Commented:
I think the problem was that you just didn't write it to the page

Commented:
here you go thanks but but not exactly fixed the problem. It shows the result but i dont want the hyperlink with that. i just need to make "AKUMAL BEACH RESORT" as a hyperlink not the star rating. What it gives me now is 4 occurances of hotel name with 4 occurances of star rating all of them are in separate lines which is perfect result.

The problem is that all of them are hyperlinked to one url. Well hyperlink to one url by resort name is okie but hyperlink to url by star rate is not good :(
CERTIFIED EXPERT

Commented:
then change

strBuild = "<div><a id=Hyperlink1 href=" & read & ">" & strResort & "</ a></div>"
Response.Write(strBuild)

to

strBuild = "<div>"  & strResort & "</div>"
Response.Write(strBuild)

Commented:
but i want to show link to resort
CERTIFIED EXPERT

Commented:
you mean it shows hyperlink with the rating?

Commented:
strBuild = "<div><a id=Hyperlink1 href=" & read & ">" & strResort & "</ a><br>"
strBuild &= "Start: " & strStar & "<br>"
strBuild &= "Room Type: " & strRoomType & "<br>"
strBuild &= "Meal: " & strMeal & "<br>"
strBuild &= "Date: " & strDate & "<br>"
strBuild &= "Duration: " & strDuration & "<br>"
strBuild &= "Price: " & strPrice & "<br>"
strBuilt &= "</div>"

Response.Write(strBuild)

This will write out the full info, with the link only on the hotel name.  I have made up the variables for the other stuff... you can use whatever you like, just getting the info from your data source of course.

John

Commented:
jnhorst

it dosn't work man ...:(

Listen YZlat

what im trying to do is to make the resort name hyperlinked and rest of the information just the text

Commented:
I mistyped the last line of code in my last post...  I put:

strBuilt &= "</div>"

Should have been

strBuild &= "</div>"

What happened when you tried my last?

John

Commented:
it shows all the information hyperlined

Commented:
You may need to check again...  My 12:47 post puts the resort name in the hyperlink and everything else outside of the hyperlink.  The variable "strResort" is what is supposed to contain the resort name only.  Maybe check and see that it does not contain all of the other info.  You need to put each item (start, type, meal, etc.) in separate variables to get where you want to go.

John
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile