Public Function format_story(ByVal stringin As String) As String

        ' As I find my stories on more and more story sites,
        ' I'm sick of story sites' auto-formatting software
        ' mucking up my stories!  So I've written an
        ' auto-formatting routine in VB and am giving it
        ' away for free.  Bear in mind that this is
        ' VB for Visual Studio .NET rather than VB 6.

        ' What it does:  Pass it a string in plain ASCII text
        ' and it returns a string with HTML codes for
        ' paragraph spacing, bold, and italics.  Also, HTML
        ' tags (any text enclosed by <>) are stripped out.

        ' What it doesn't do:  It doesn' support fancy
        ' text-based formatting commands such as {green} or
        ' {bold}.

        ' How it works:  It scans the input string, character by
        ' character...
        ' -  When it finds a newline character, it inserts TWO
        '    HTML line break codes for double spacing followed
        '    by a string of four non-breaking spaces, tnen skips
        '    the subsequent input text until it comes to the
        '    next alphanumeric character (i.e. it skips following
        '    newline characters and spaces).  This way, all
        '    stories wil be double-spaced and indented between
        '    paragraphs regardless whether the author single- or
        '    double-spaces his paragraphs or indents them.
        ' -  When it finds a "<" character, it skips over the
        '    subsequent text until it comes to a ">" character;
        '    thus preventing authors from embedding HTML in their
        '    stories.
        ' -  When it finds a "_" character, it inserts an HTML
        '    tag to turn italics on if italics is off, or to
        '    turn italics off if italics is on.
        ' -  When it finds a "*" character, it inserts an HTML
        '    tag to turn bold on if bold is off, or to
        '    turn bold off if bold is on.

        ' This code is copyright (c) 2003 Hungry Guy, but I give
        ' permission for operators of free story sites to use
        ' it as-is, or with your own improvements, in order to
        ' improve the quality of your auto-formatting functions.

        ' If you want minor tweaks or changes, feel free to ask
        ' and I'll see what I can do in my spare time.  But if
        ' you want major revisions to the code, you'll need
        ' to hire me as a full-time software engineer.

        Dim str1 As String
        Dim ix1 As Integer
        Dim str2 As String
        Dim str3_br As String
        Dim len3 As Integer
        Dim chr1 As Char
        Dim ital As Boolean
        Dim bold As Boolean

        ital = False
        bold = False
        ix1 = 1
        str1 = stringin + "    "
        str2 = " "
        str3_br = "<BR><BR>    "
        len3 = str3_br.Length - 2

        While (ix1 < str1.Length)
            chr1 = Mid(str1, ix1, 1)
            If (chr1 < " ") Then
                str2 = Mid(str1, 1, ix1 - 1) + str3_br
                While (Mid(str1, ix1, 1) <= " ") And (ix1 < str1.Length)
                    ix1 = ix1 + 1
                End While
                str1 = str2 + Mid(str1, ix1, str1.Length)
                ix1 = ix1 + len3
            ElseIf (chr1 = "<") Then
                str2 = Mid(str1, 1, ix1 - 1)
                ix1 = ix1 + 1
                While (Mid(str1, ix1, 1) <> ">") And (ix1 < str1.Length)
                    ix1 = ix1 + 1
                End While
                ix1 = ix1 + 1
                str1 = str2 + Mid(str1, ix1, str1.Length)
            ElseIf (chr1 = "_") Then
                If (ital) Then
                    str2 = Mid(str1, 1, ix1 - 1) + "</I>"
                    ital = False
                Else
                    str2 = Mid(str1, 1, ix1 - 1) + "<I>"
                    ital = True
                End If
                ix1 = ix1 + 1
                str1 = str2 + Mid(str1, ix1, str1.Length)
            ElseIf (chr1 = "*") Then
                If (bold) Then
                    str2 = Mid(str1, 1, ix1 - 1) + "</B>"
                    bold = False
                Else
                    str2 = Mid(str1, 1, ix1 - 1) + "<B>"
                    bold = True
                End If
                ix1 = ix1 + 1
                str1 = str2 + Mid(str1, ix1, str1.Length)
            End If
            ix1 = ix1 + 1
        End While
        If (ital) Then
            str1 = str1 + "</I>"
            ital = False
        End If
        If (bold) Then
            str1 = str1 + "</B>"
            bold = False
        End If
        str1 = "<BR>    " + str1
        Return (str1)
    End Function