VB6Parse / Library / String / lcase_dollar

VB6 Library Reference

LCase$ Function

Returns a String that has been converted to lowercase. The "$" suffix indicates this function returns a String type.

Syntax

LCase$(string)

Parameters

Returns

Returns a String with all uppercase letters converted to lowercase. Numbers and punctuation are unchanged.

Remarks

Typical Uses

  1. Case-insensitive comparisons - Compare strings without regard to case
  2. User input normalization - Convert user input to a consistent case
  3. Email address handling - Normalize email addresses to lowercase
  4. File path comparisons - Compare file paths on case-insensitive file systems
  5. Username validation - Normalize usernames to lowercase
  6. Search operations - Perform case-insensitive searches
  7. Data standardization - Ensure consistent casing in databases

Basic Examples

' Example 1: Simple conversion
Dim result As String
result = LCase$("HELLO")  ' Returns "hello"
' Example 2: Mixed case
Dim text As String
text = LCase$("Hello World")  ' Returns "hello world"
' Example 3: With numbers and punctuation
Dim mixed As String
mixed = LCase$("ABC123!@#")  ' Returns "abc123!@#"
' Example 4: Already lowercase
Dim lower As String
lower = LCase$("already lowercase")  ' Returns "already lowercase"

Common Patterns

Case-Insensitive Comparison

Function CompareIgnoreCase(str1 As String, str2 As String) As Boolean
    CompareIgnoreCase = (LCase$(str1) = LCase$(str2))
End Function

Normalize User Input

Function NormalizeInput(userInput As String) As String
    NormalizeInput = Trim$(LCase$(userInput))
End Function

Email Address Normalization

Function NormalizeEmail(email As String) As String
    NormalizeEmail = LCase$(Trim$(email))
End Function
Function ContainsIgnoreCase(text As String, searchFor As String) As Boolean
    ContainsIgnoreCase = (InStr(LCase$(text), LCase$(searchFor)) > 0)
End Function

Username Validation

Function ValidateUsername(username As String) As String
    ' Normalize to lowercase
    ValidateUsername = LCase$(Trim$(username))
End Function

File Extension Check

Function HasExtension(filename As String, ext As String) As Boolean
    Dim fileExt As String
    fileExt = LCase$(Right$(filename, Len(ext)))
    HasExtension = (fileExt = LCase$(ext))
End Function

Dictionary Key Normalization

Sub AddToDictionary(dict As Object, key As String, value As Variant)
    dict.Add LCase$(key), value
End Sub

Case-Insensitive Replace

Function ReplaceIgnoreCase(text As String, findText As String, replaceWith As String) As String
    Dim lowerText As String
    Dim lowerFind As String
    Dim pos As Long
    lowerText = LCase$(text)
    lowerFind = LCase$(findText)
    pos = InStr(lowerText, lowerFind)
    If pos > 0 Then
        ReplaceIgnoreCase = Left$(text, pos - 1) & replaceWith & Mid$(text, pos + Len(findText))
    Else
        ReplaceIgnoreCase = text
    End If
End Function

Sort Key Generation

Function GenerateSortKey(text As String) As String
    GenerateSortKey = LCase$(Trim$(text))
End Function

Command Parser

Function ParseCommand(input As String) As String
    Dim cmd As String
    cmd = LCase$(Trim$(input))
    Select Case cmd
        Case "help"
            ParseCommand = "ShowHelp"
        Case "exit", "quit"
            ParseCommand = "Exit"
        Case Else
            ParseCommand = "Unknown"
    End Select
End Function

Advanced Examples

Case-Insensitive Collection Lookup

Function FindInCollection(col As Collection, key As String) As Variant
    On Error Resume Next
    Dim lowerKey As String
    Dim item As Variant
    Dim i As Long
    lowerKey = LCase$(key)
    ' Try direct lookup first
    FindInCollection = col(lowerKey)
    If Err.Number <> 0 Then
        ' Not found, search manually
        Err.Clear
        For i = 1 To col.Count
            If LCase$(col(i)) = lowerKey Then
                FindInCollection = col(i)
                Exit Function
            End If
        Next i
    End If
End Function

SQL Query Builder

Function BuildWhereClause(fieldName As String, operator As String, value As String) As String
    Dim op As String
    op = LCase$(Trim$(operator))
    Select Case op
        Case "equals", "="
            BuildWhereClause = fieldName & " = '" & value & "'"
        Case "contains", "like"
            BuildWhereClause = fieldName & " LIKE '%" & value & "%'"
        Case "startswith"
            BuildWhereClause = fieldName & " LIKE '" & value & "%'"
        Case Else
            BuildWhereClause = ""
    End Select
End Function

Configuration File Parser

Function ParseConfigLine(line As String, ByRef key As String, ByRef value As String) As Boolean
    Dim pos As Long
    Dim trimmedLine As String
    trimmedLine = Trim$(line)
    ' Skip comments and empty lines
    If Len(trimmedLine) = 0 Or Left$(trimmedLine, 1) = "#" Then
        ParseConfigLine = False
        Exit Function
    End If
    pos = InStr(trimmedLine, "=")
    If pos > 0 Then
        key = LCase$(Trim$(Left$(trimmedLine, pos - 1)))
        value = Trim$(Mid$(trimmedLine, pos + 1))
        ParseConfigLine = True
    Else
        ParseConfigLine = False
    End If
End Function

Smart String Comparison

Function SmartCompare(str1 As String, str2 As String, caseSensitive As Boolean) As Boolean
    If caseSensitive Then
        SmartCompare = (str1 = str2)
    Else
        SmartCompare = (LCase$(str1) = LCase$(str2))
    End If
End Function

Error Handling

Function SafeLCase(text As String) As String
    On Error GoTo ErrorHandler
    If IsNull(text) Then
        SafeLCase = ""
        Exit Function
    End If
    SafeLCase = LCase$(text)
    Exit Function
ErrorHandler:
    SafeLCase = ""
End Function

Performance Notes

Best Practices

  1. Use for comparisons - Always normalize case when doing case-insensitive comparisons
  2. Prefer LCase$ over LCase - Use LCase$ when you know the result is a string
  3. Cache results - Store lowercase versions rather than converting repeatedly
  4. Handle Null - Check for Null values before calling LCase$
  5. Combine with Trim - Often useful to combine LCase$ with Trim$ for user input
  6. Document intent - Make it clear when lowercase conversion is for comparison vs. display
  7. Consider locale - Be aware that conversion may vary by system locale
Function Return Type Conversion Use Case
LCase Variant To lowercase When working with Variant types
LCase$ String To lowercase When result is definitely a string
UCase Variant To uppercase Convert to uppercase (Variant)
UCase$ String To uppercase Convert to uppercase (String)
StrConv String Various conversions Complex case conversions

Common Use Cases

Case-Insensitive String Arrays

Function ArrayContains(arr() As String, value As String) As Boolean
    Dim i As Long
    Dim lowerValue As String
    lowerValue = LCase$(value)
    For i = LBound(arr) To UBound(arr)
        If LCase$(arr(i)) = lowerValue Then
            ArrayContains = True
            Exit Function
        End If
    Next i
    ArrayContains = False
End Function

URL Parameter Parsing

Function GetURLParameter(url As String, paramName As String) As String
    Dim lowerURL As String
    Dim lowerParam As String
    Dim startPos As Long
    Dim endPos As Long
    lowerURL = LCase$(url)
    lowerParam = LCase$(paramName) & "="
    startPos = InStr(lowerURL, lowerParam)
    If startPos > 0 Then
        startPos = startPos + Len(lowerParam)
        endPos = InStr(startPos, url, "&")
        If endPos = 0 Then endPos = Len(url) + 1
        GetURLParameter = Mid$(url, startPos, endPos - startPos)
    End If
End Function

Platform Notes

Limitations

← Back to String | View all functions