by L Tropa (2 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 18th May 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)
'This Function Allows you to put to Lower Case any unwanted words you want within a string (doesn't matter its size) contained in a Control or
API Declarations
ex: TextBox1 = ConverterTexto(TextBox1)
Dim StrSearched(1 To 12) As String, NStr As Integer, Dividir, NDiv As Integer, StrSearching As Integer
On Error Resume Next
'if the String to Convert is zero-lengh..
If Len(StrAConverter) = 0 Then Exit Function
'Creating a "one dimension" Array with all the Words you want to replace,
'if found (in this case 12 words). Kind like a Mini-DataBase of Words.
'I tested this Function in VBA (on the "Exit" procedure of a TextBox Control) but you can test it yourself in VB perhaps in the "LostFocus" procedure. I think that it will work in any Control thal accepts Text or Caption
'The words mencioned bellow are in Portuguese but you can replace them with any other in your language (" Or ", " Of ", " The ", etc).
'Don't forget, however, to redimention the Array if you plan to add more than 12 Words to it
StrSearched(1) = " de "
StrSearched(2) = " da "
StrSearched(3) = " do "
StrSearched(4) = " o "
StrSearched(5) = " a "
StrSearched(6) = " das "
StrSearched(7) = " dos "
StrSearched(8) = " ao "
StrSearched(9) = " aos "
StrSearched(10) = " as "
StrSearched(11) = " os "
StrSearched(12) = " e "
'Spliting de String contained in the TextBox or other Control that supports Text
Dividir = Split(StrAConverter, , -1, vbTextCompare)
'Searching for each of the Words contained in StrSearched (or the ones you choose) within
' the Array variable "Dividir" created by the Split Function
For NDiv = 0 To UBound(Dividir)
For NStr = 1 To UBound(StrSearched)
StrSearching = InStr(1, " " & Dividir(NDiv) & " ", StrSearched(NStr), vbTextCompare)
If StrSearching > 0 Then ' If found...then put it to LowerCase
Dividir(NDiv) = StrConv(Dividir(NDiv), vbLowerCase)
NDiv = NDiv + 1
Else ' in the other hand if it's not found put the String to ProperCase
Dividir(NDiv) = StrConv(Dividir(NDiv), vbProperCase)
End If
Next NStr
Next NDiv
ConverterTexto = Trim(Join(Dividir))
StrAConverter = ConverterTexto
End Function
No comments have been posted about 'This Function Allows you to put to Lower Case any unwanted words you want within a string (doesn't. Why not be the first to post a comment about 'This Function Allows you to put to Lower Case any unwanted words you want within a string (doesn't.