write part of a string using asp.net

Results 1 to 2 of 2

Thread: write part of a string using asp.net

  1. #1
    Join Date
    Dec 1969

    Default write part of a string using asp.net

    Hi, <BR><BR>I am new to asp and am trying to create a file that grabs data from a web site and output a specific part of that data (the weather for an Australian city).<BR><BR>I have managed to grab the data from the URL and then find the location of the data I want using instr() function. <BR><BR>I just don&#039;t know how to output the data from that specific point in the string.<BR><BR>Any help or advice on what functions or commands to use would be much appreciated.<BR><BR>Thanks,<BR><BR>Michael<BR><BR> code:<BR><BR>&#060;%@ Import Namespace="System.Net" %&#062; <BR>&#060;script language="VB" runat="server"&#062; <BR>Sub Page_Load(sender as Object, e as EventArgs) <BR><BR>&#039;Create a WebClient instance <BR>Dim objWebClient as New WebClient() <BR><BR><BR><BR>Const strURL as String = "http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDQ10090.txt" <BR><BR>Dim sItem as String<BR>Dim lblHTMLOutput as String<BR><BR>Dim objUTF8 as New UTF8Encoding() <BR>lblHTMLOutput = objUTF8.GetString(objWebClient.DownloadData(strURL )) <BR><BR>sItem=lblHTMLOutput<BR>sItem=instr(1, lblHTMLOutput, "GOLD COAST")<BR>response.Write (sItem)<BR><BR>End Sub <BR>&#060;/script&#062; <BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: write part of a string using asp.net

    You can either use the Visual Basic "Mid" function or the .NET Framework String.Substring *method* to grab sub-sections of a string. To do that you need to:<BR><BR> - find the starting position (either InStr [VB] or IndexOf [.NET])<BR> - *read* through the string (using Mid [VB] or SubString [.NET]) until you find the end of what you are looking for<BR> - use Mid [VB] or SubString [.NET] to grab the characters between the starting position and the ending position.<BR><BR>You could also use a Regular Expression to look for your text based on a pattern.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts