Viewing source for Recipe1711vb.aspx
<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>
<script language="VB" runat="server">
Protected Sub Page_Load(ByVal Source As Object, ByVal e As EventArgs)
WordsLabel.Text = GetWordsFromFile(Server.MapPath("starwarquotes.txt"))
End Sub
Private Function GetWordsFromFile(ByVal filename As String) As String
Dim sr As StreamReader = Nothing
Dim delimiter() As Char = {"\u0009"," "} 'tab and space
Dim sb As StringBuilder = New StringBuilder()
Try
sr = File.OpenText(filename)
Dim line As String = sr.ReadLine()
While Not line Is Nothing
'split the line into words
Dim words() As String = line.Split(delimiter)
Dim word As String
For Each word In words
If word.EndsWith("r") Then
sb.Append(word)
sb.Append("<br>")
End If
Next
line = sr.ReadLine()
End While
Catch ex As Exception
If sb.Length > 0 Then
sb.Remove(0,sb.Length-1)
End If
sb.Append(ex.Message)
Finally
If Not sr Is Nothing Then
sr.Close()
End If
End Try
Return sb.ToString()
End Function
</script>
<html>
<body>
<form runat="server">
<asp:Label id="WordsLabel" runat="server" />
<hr>
<a href="starwarquotes.txt">Quotes File</a>
</form>
</body>
</html>