[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 344
  • Last Modified:

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.IndexOf(">") + 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(cheapStr.LastIndexOf("<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.......?
0
shwaqar82
Asked:
shwaqar82
  • 10
  • 9
  • 4
  • +1
3 Solutions
 
deanvanrooyenCommented:
di you try

cheapStr &=  "<br />"
0
 
jnhorstCommented:
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
0
 
YZlatCommented:
try

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

or

 cheapStr = cheapStr & "<br>"
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
shwaqar82Author 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()
            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.IndexOf("<nobr>") + 6, read.IndexOf("</nobr>") - read.IndexOf("<nobr>") - 6) 'Resort Name
                    'MsgBox(read.Substring(read.IndexOf("<nobr>") + 6, read.IndexOf("</nobr>") - read.IndexOf("<nobr>") - 6))
                    read = read.Substring(read.IndexOf("'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.IndexOf("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>
0
 
YZlatCommented:
what result does your code produces now?
0
 
shwaqar82Author 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
0
 
YZlatCommented:
try replacing this line
  read = read.Substring(read.IndexOf("style2" & Chr(34) & ">") + 8, 1).Trim
with

  read = read.Substring(read.IndexOf("style2" & Chr(34) & ">"), 1).Trim
0
 
shwaqar82Author Commented:
doesn't make any difference
0
 
YZlatCommented:
read = read.Substring(read.IndexOf("style2")+2, 1).Trim

or

read = read.Substring(read.IndexOf("style2")+1, 1).Trim

0
 
shwaqar82Author Commented:
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&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>
0
 
YZlatCommented:
did you try debugging to make sure

 read = strmRead.ReadLine()

gets the correct line?
0
 
shwaqar82Author Commented:
well i did and its giviing me the exact code which i want to display on the page:

read = read.Substring(read.IndexOf("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
0
 
YZlatCommented:
try changing this line
 strBuild &= "<div>" & read & "</div>"   'Star Rate

to

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


0
 
YZlatCommented:
actually change

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

to

  strBuild &= "<div>" & read & "</div>"   'Star Rate
                   Response.write(strBuild)
0
 
YZlatCommented:
I think the problem was that you just didn't write it to the page
0
 
shwaqar82Author 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 :(
0
 
YZlatCommented:
then change

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

to

    strBuild = "<div>"  & strResort & "</div>"
                    Response.Write(strBuild)
0
 
shwaqar82Author Commented:
but i want to show link to resort
0
 
YZlatCommented:
you mean it shows hyperlink with the rating?
0
 
jnhorstCommented:
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
0
 
shwaqar82Author 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
0
 
jnhorstCommented:
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
0
 
shwaqar82Author Commented:
it shows all the information hyperlined
0
 
jnhorstCommented:
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
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 10
  • 9
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now