Results 1 to 7 of 7

Thread: Strings - UCase and LCase (with HTML tags)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    28

    Question Strings - UCase and LCase (with HTML tags)

    Ok, so heres the problem:

    I am in the process of making a HTML editor, and I have a tool which (at the moment) converts tag case to uppercase or lowercase. The only problem is it also converts the attributes as well, which I don't want. Does anyone know how to ignore the attributes and change the case for the rest of the tag? I have included the source code that I am currently using below (for uppercase).

    Oh, and btw, I'm a newbie, so plz give me some code (or tell me where I can find some) rather then tell me what vb function to use.

    Thanks,

    Tom
    [email protected]

    Here's the current code:

    Code:
    Sub TagUCase()
    Dim txt As String
    Dim tag_open As Integer
    Dim tag_close As Integer
    On Error GoTo ErrorHandler
    rchEditor.Visible = False
    Screen.MousePointer = vbHourglass
    txt = rchEditor.Text
    tag_close = 1
    Do
    tag_open = InStr(tag_close, txt, "<")
    If tag_open = 0 Then Exit Do
    tag_close = InStr(tag_open + 1, txt, ">")
    If tag_open = 0 Then tag_close = Len(txt)
    rchEditor.SelStart = tag_open - 1
    rchEditor.SelLength = tag_close - tag_open + 1
    rchEditor.SelText = UCase(rchEditor.SelText)
    rchEditor.SelStart = 0
    Loop
    rchEditor.Visible = True
    Screen.MousePointer = vbNormal
    rchEditor.SetFocus
    
    
    ErrorHandler:
    rchEditor.Visible = True
    Screen.MousePointer = vbNormal
    Exit Sub
    End Sub

  2. #2
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    This converts the tag only
    Code:
    Private Sub Command1_Click()
        Dim iPos As Integer
        Dim sTag As String
        Dim sTagHolder
        
        sTag = Text1.Text
        iPos = InStr(2, sTag, Space(1))
        
        sTagHolder = Split(sTag, Space(1))
        sTagHolder(0) = UCase(sTagHolder(0))
        
        sTag = Join(sTagHolder, Space(1))
        
        Text1.Text = sTag
        
    End Sub

  3. #3
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    This code will convert the atributes to uppercase but not the attribute value. for example
    <img src="image.gif">
    to
    <IMG SRC="image.gif">

    Here is the function just pass it the tag
    Code:
    
    Here is the Function
    Function ConvertHTMLTags(ByVal HTMLTAG) As String
        Dim sTag As String
        Dim i As Integer
        Dim iLen As Integer
        
        sTag = HTMLTAG
        iLen = Len(sTag)
        
        For i = 1 To iLen
            If Mid(sTag, i, 1) = """" Then
                ipos = InStr(i + 1, sTag, """")
                Do Until i = ipos + 1
                    If i > iLen Then
                        i = i - 1
                        Exit Do
                    Else
                        stagholder = stagholder & Mid(sTag, i, 1)
                    End If
                    i = i + 1
                Loop
            End If
            stagholder = stagholder & UCase(Mid(sTag, i, 1))
        Next
        ConvertHTMLTags = stagholder
    End Function
    Last edited by jjortiz; May 13th, 2001 at 01:17 PM.

  4. #4
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    You can also check in the following way. Start at the first = sign and loop till you get to the first space. Just in case someone did not use quotation marks.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    28
    Thanks alot for this, I'll try it out and report back if I have any problems.

    Cheers,

    Tom
    [email protected]

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    28
    Well it kinda worked, but it struggles with large files, and does things like:

    Code:
    </foNT>
    Or it just returns a overflow error.

    Apart from that it works fine (although I did have to modify it a bit).

    Oh and btw, I don't suppose any of you have Dreamweaver UltraDev versions 3 or 4 do you? I just need to know a few things about it.

    Cheers,

    Tom
    [email protected]

  7. #7
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    That snippet of code was written very quickly. I will take a look at it again and then revise it.

Posting Permissions

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



Click Here to Expand Forum to Full Width