Solved

how to append new line character in string variable

Posted on 2006-10-29
24
310 Views
Last Modified: 2008-02-01
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
Comment
Question by:shwaqar82
  • 10
  • 9
  • 4
  • +1
24 Comments
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 250 total points
ID: 17830857
di you try

cheapStr &=  "<br />"
0
 
LVL 10

Assisted Solution

by:jnhorst
jnhorst earned 50 total points
ID: 17831465
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
 
LVL 35

Expert Comment

by:YZlat
ID: 17835639
try

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

or

 cheapStr = cheapStr & "<br>"
0
 

Author Comment

by:shwaqar82
ID: 17836045
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
 
LVL 35

Expert Comment

by:YZlat
ID: 17836121
what result does your code produces now?
0
 

Author Comment

by:shwaqar82
ID: 17836253
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
 
LVL 35

Expert Comment

by:YZlat
ID: 17836306
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
 

Author Comment

by:shwaqar82
ID: 17836330
doesn't make any difference
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17836345
read = read.Substring(read.IndexOf("style2")+2, 1).Trim

or

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

0
 

Author Comment

by:shwaqar82
ID: 17836374
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
 
LVL 35

Expert Comment

by:YZlat
ID: 17836399
did you try debugging to make sure

 read = strmRead.ReadLine()

gets the correct line?
0
 

Author Comment

by:shwaqar82
ID: 17836481
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 35

Expert Comment

by:YZlat
ID: 17836497
try changing this line
 strBuild &= "<div>" & read & "</div>"   'Star Rate

to

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


0
 
LVL 35

Assisted Solution

by:YZlat
YZlat earned 200 total points
ID: 17836505
actually change

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

to

  strBuild &= "<div>" & read & "</div>"   'Star Rate
                   Response.write(strBuild)
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17836508
I think the problem was that you just didn't write it to the page
0
 

Author Comment

by:shwaqar82
ID: 17836617
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
 
LVL 35

Expert Comment

by:YZlat
ID: 17837069
then change

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

to

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

Author Comment

by:shwaqar82
ID: 17837084
but i want to show link to resort
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17837143
you mean it shows hyperlink with the rating?
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 17837158
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
 

Author Comment

by:shwaqar82
ID: 17837359
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
 
LVL 10

Expert Comment

by:jnhorst
ID: 17837406
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
 

Author Comment

by:shwaqar82
ID: 17837425
it shows all the information hyperlined
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 17837710
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

20 Experts available now in Live!

Get 1:1 Help Now