Text to HTML Learn programming Visual Basic (VB.net)


OOP More On Classes


Text to HTML


Create a class "TextToHTML", which must be able to convert several texts entered by the user into a HTML sequence, like this one:

Soy yo
Ya he terminado

should become


Soy yo

Ya he terminado

The class must contain:
An array of strings
A method "Add", to include a new string in it
A method "Display", to show its contents on screen
A method "ToString", to return a string containing all the texts, separated by "\n".
Create also an auxiliary class containing a "Main" function, to help you test it.


Imports System
Class TextToHTML
    Protected myHTML As String()
    Protected maxLines As Integer = 1000
    Private counter As Integer = 0

    Public Sub New()
        myHTML = New String(maxLines - 1) {}
    End Sub

    Public Sub Add(ByVal newSentence As String)
        If counter < maxLines Then
            myHTML(counter) = newSentence
            counter += 1
        End If
    End Sub

    Public Function ToString() As String
        Dim allHTML As String = vbLf & vbLf

        For i As Integer = 0 To counter - 1
            allHTML += myHTML(i)
            allHTML += vbLf

        allHTML += vbLf
        allHTML += vbLf
        Return allHTML
    End Function

    Public Sub Display()
    End Sub
End Class

Class TextTest
    Private Shared Sub Main(ByVal args As String())
        Dim example As TextToHTML = New TextToHTML()
        example.Add("uno dos")
        example.Add("tres cuatro")
    End Sub
End Class

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.