shwaqar82
asked on
how to append new line character in string variable
Hi Experts
I have the following code:
While read <> "</html>"
If read.IndexOf("<tr bgcolor=" & Chr(34) & "#FFFFFF" & Chr(34) & ">") <> -1 Then 'find the cheapest price in this page
Do
If read.IndexOf(".jpg") = -1 And read.IndexOf(".gif") = -1 Then
cheapStr &= read & Chr(13) & Chr(10)
End If
If read.IndexOf("$") <> -1 Then 'Get the price
For i As Integer = 0 To 1
read = read.Substring(read.IndexO f(">") + 1) & Chr(13) & Chr(10)
Next
cheapPrice = read.Substring(1, read.IndexOf("<") - 1) 'All the prices here
If Double.Parse(cheapPrice) < cheapestprice Then
cheapestprice = Double.Parse(cheapPrice) 'Cheapest Price here
renew = True
If renew Then
cheapeststr = cheapStr.Substring(cheapSt r.LastInde xOf("<tr bgcolor=" & Chr(34) & "#FFFFFF" & Chr(34) & ">"))
End If
End If
End If
read = strmRead.ReadLine()
Loop While read.IndexOf("</tr>") = -1
cheapStr &= Chr(13) & Chr(10)
End If
read = strmRead.ReadLine
End While
strmRead.Close()
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.......?
I have the following code:
While read <> "</html>"
If read.IndexOf("<tr bgcolor=" & Chr(34) & "#FFFFFF" & Chr(34) & ">") <> -1 Then 'find the cheapest price in this page
Do
If read.IndexOf(".jpg") = -1 And read.IndexOf(".gif") = -1 Then
cheapStr &= read & Chr(13) & Chr(10)
End If
If read.IndexOf("$") <> -1 Then 'Get the price
For i As Integer = 0 To 1
read = read.Substring(read.IndexO
Next
cheapPrice = read.Substring(1, read.IndexOf("<") - 1) 'All the prices here
If Double.Parse(cheapPrice) < cheapestprice Then
cheapestprice = Double.Parse(cheapPrice) 'Cheapest Price here
renew = True
If renew Then
cheapeststr = cheapStr.Substring(cheapSt
End If
End If
End If
read = strmRead.ReadLine()
Loop While read.IndexOf("</tr>") = -1
cheapStr &= Chr(13) & Chr(10)
End If
read = strmRead.ReadLine
End While
strmRead.Close()
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.......?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.cg i" method=post>
<input type=hidden name=sid value="c319599a55230c2a9a1 0778b6cb91 92b">
<input type=hidden name=result value="dc5315d5950b5e6f9d1 0fa3879b94 c4">
<input type=hidden name=language value="">
<td align=left bgcolor="ffffff"><span class="style2">CANCUN</spa n></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>A KUMAL BEACH RESORT</nobr></a></span></ td>
<td align=center bgcolor="ffffff"><span class="style2">3</span></t d>
<td align=center bgcolor="ffffff"><span class="style2">STD-GARD</s pan></td>
<td align=center bgcolor="ffffff"><span class="style2">AI</span></ td>
<td align=center bgcolor="ffffff"><span class="style2">NOV-15-2006 </span></t d>
<td align=center bgcolor="ffffff"><span class="style2">7</span></t d>
<td align=center bgcolor="ffffff"><span class="style2">$967.00</sp an></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()
strmRead = New StreamReader(strm)
read = strmRead.ReadLine()
renew = False
While read <> "</html>"
If read.IndexOf("<form action=") <> -1 Then
read = strmRead.ReadLine()
read = strmRead.ReadLine()
read = strmRead.ReadLine()
read = strmRead.ReadLine()
read = strmRead.ReadLine()
read = strmRead.ReadLine()
'strbuild = "<asp:Hyperlink ID=Hyperlink1 runat=server NavigateUrl=" &
strResort = read.Substring(read.IndexO f("<nobr>" ) + 6, read.IndexOf("</nobr>") - read.IndexOf("<nobr>") - 6) 'Resort Name
'MsgBox(read.Substring(rea d.IndexOf( "<nobr>") + 6, read.IndexOf("</nobr>") - read.IndexOf("<nobr>") - 6))
read = read.Substring(read.IndexO f("'http://") + 1, read.IndexOf("html") - read.IndexOf("'http://") + 3) 'Resort Link
strBuild = "<div><a id=Hyperlink1 href=" & read & ">" & strResort & "</ a></div>"
Response.Write(strBuild)
read = strmRead.ReadLine() 'Star rating line
read = read.Substring(read.IndexO f("style2" & Chr(34) & ">") + 8, 1).Trim
strBuild &= "<div>" & read & "</div>" 'Star Rate
MsgBox(strBuild)
strBuild = Nothing
End If
read = strmRead.ReadLine()
End While
strmRead.Close()
strm.Close()
webRes.Close()
I want the result to show up on display like that:
Hotel: AKUMAL BEACH RESORT
Star: 3
Room Type: STD-GRAD
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>
I have several of these lines of code in my aspx page "View Source":
<form action="input-verifforf.cg
<input type=hidden name=sid value="c319599a55230c2a9a1
<input type=hidden name=result value="dc5315d5950b5e6f9d1
<input type=hidden name=language value="">
<td align=left bgcolor="ffffff"><span class="style2">CANCUN</spa
<td align=left bgcolor="ffffff"><span class="style2">
<a href="javascript:popWinS('
<td align=center bgcolor="ffffff"><span class="style2">3</span></t
<td align=center bgcolor="ffffff"><span class="style2">STD-GARD</s
<td align=center bgcolor="ffffff"><span class="style2">AI</span></
<td align=center bgcolor="ffffff"><span class="style2">NOV-15-2006
<td align=center bgcolor="ffffff"><span class="style2">7</span></t
<td align=center bgcolor="ffffff"><span class="style2">$967.00</sp
</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()
strmRead = New StreamReader(strm)
read = strmRead.ReadLine()
renew = False
While read <> "</html>"
If read.IndexOf("<form action=") <> -1 Then
read = strmRead.ReadLine()
read = strmRead.ReadLine()
read = strmRead.ReadLine()
read = strmRead.ReadLine()
read = strmRead.ReadLine()
read = strmRead.ReadLine()
'strbuild = "<asp:Hyperlink ID=Hyperlink1 runat=server NavigateUrl=" &
strResort = read.Substring(read.IndexO
'MsgBox(read.Substring(rea
read = read.Substring(read.IndexO
strBuild = "<div><a id=Hyperlink1 href=" & read & ">" & strResort & "</ a></div>"
Response.Write(strBuild)
read = strmRead.ReadLine() 'Star rating line
read = read.Substring(read.IndexO
strBuild &= "<div>" & read & "</div>" 'Star Rate
MsgBox(strBuild)
strBuild = Nothing
End If
read = strmRead.ReadLine()
End While
strmRead.Close()
strm.Close()
webRes.Close()
I want the result to show up on display like that:
Hotel: AKUMAL BEACH RESORT
Star: 3
Room Type: STD-GRAD
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>
what result does your code produces now?
ASKER
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
any help plz
try replacing this line
read = read.Substring(read.IndexO f("style2" & Chr(34) & ">") + 8, 1).Trim
with
read = read.Substring(read.IndexO f("style2" & Chr(34) & ">"), 1).Trim
read = read.Substring(read.IndexO
with
read = read.Substring(read.IndexO
ASKER
doesn't make any difference
read = read.Substring(read.IndexO f("style2" )+2, 1).Trim
or
read = read.Substring(read.IndexO f("style2" )+1, 1).Trim
or
read = read.Substring(read.IndexO
ASKER
my working code generates the below view source:
<div><a id=Hyperlink1 href=http://webstar.softvoyage.com/cgi-bin/hotel_desc.cgi?sun&&http://webstar.softvoyage.com/hotels/VACen/AKUMCUN.html>AKUMAL BEACH RESORT</ a></div><div><a id=Hyperlink1 href=http://webstar.softvoyage.com/cgi-bin/hotel_desc.cgi?sun&&http://webstar.softvoyage.com/hotels/VACen/AKUMCUN.html>AKUMAL BEACH RESORT</ a></div>
<!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" >
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="Backnew.aspx?code_ ag=sun& ;alias=sun &gatew ay_dep=YYZ &dest_ dep=CUN&am p;duration =7&dep arture_mon th=11& departure_ day=16& ;departure _day_to=30 &depar ture_month _to=11& ;no_hotel= 1346&s tar=3& flex=Y& ;price_max =99999& ;searchtyp e=FO" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTUxMzcyMjQ yN2RkY7KD7 tf88gE+uOM tbRrLaAa0j pE=" />
</div>
<div>
<br />
</form>
</body>
</html>
<div><a id=Hyperlink1 href=http://webstar.softvoyage.com/cgi-bin/hotel_desc.cgi?sun&&http://webstar.softvoyage.com/hotels/VACen/AKUMCUN.html>AKUMAL BEACH RESORT</ a></div><div><a id=Hyperlink1 href=http://webstar.softvoyage.com/cgi-bin/hotel_desc.cgi?sun&&http://webstar.softvoyage.com/hotels/VACen/AKUMCUN.html>AKUMAL BEACH RESORT</ a></div>
<!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" >
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="Backnew.aspx?code_
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTUxMzcyMjQ
</div>
<div>
<br />
</form>
</body>
</html>
did you try debugging to make sure
read = strmRead.ReadLine()
gets the correct line?
read = strmRead.ReadLine()
gets the correct line?
ASKER
well i did and its giviing me the exact code which i want to display on the page:
read = read.Substring(read.IndexO f("style2" & Chr(34) & ">") + 8, 1).Trim
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
read = read.Substring(read.IndexO
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
try changing this line
strBuild &= "<div>" & read & "</div>" 'Star Rate
to
strBuild =StrBuild & "<div><b>" & read & "</b></div>" 'Star Rate
strBuild &= "<div>" & read & "</div>" 'Star Rate
to
strBuild =StrBuild & "<div><b>" & read & "</b></div>" 'Star Rate
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think the problem was that you just didn't write it to the page
ASKER
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 :(
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 :(
then change
strBuild = "<div><a id=Hyperlink1 href=" & read & ">" & strResort & "</ a></div>"
Response.Write(strBuild)
to
strBuild = "<div>" & strResort & "</div>"
Response.Write(strBuild)
strBuild = "<div><a id=Hyperlink1 href=" & read & ">" & strResort & "</ a></div>"
Response.Write(strBuild)
to
strBuild = "<div>" & strResort & "</div>"
Response.Write(strBuild)
ASKER
but i want to show link to resort
you mean it shows hyperlink with the rating?
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
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
ASKER
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
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
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
strBuilt &= "</div>"
Should have been
strBuild &= "</div>"
What happened when you tried my last?
John
ASKER
it shows all the information hyperlined
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
John
cheapStr = cheapStr & Chr(13) & Chr(10)
or
cheapStr = cheapStr & "<br>"