Monday, April 17, 2006
Case Changer Excluding Literals
Usage:
Dim x as string
x = "I like to 'Eat','EAT','eat', Apples and Bananas."
x = CaseChangeExcludingLiterals(x,True,"'")
x now equals: "I LIKE TO 'Eat','EAT','eat',APPLES AND BANANAS."
Private Function CaseChangerExcludingLiterals(ByVal Source As String, Optional ByValAs Boolean = True, Optional ByVal LiteralIdentifier As Char = Chr(34)) As String ToUpper
Dim SourceReturn As String = ""
Dim InsideQuotes As Boolean = False
For Each SourceCharacter As Char In Source
If SourceCharacter = LiteralIdentifier Then
SourceReturn &= SourceCharacter
If InsideQuotes Then
InsideQuotes = False
Else
InsideQuotes = True
End If
Else
If InsideQuotes Then
SourceReturn &= SourceCharacter
Else
If ToUpper Then
SourceReturn &= Char.ToUpper(SourceCharacter)
Else
SourceReturn &= Char.ToLower(SourceCharacter)
End If
End If
End If
Next
Return SourceReturn
End Function