Proper case function! hi! iT is CoOl -> Hi! It is cool
To fix the input of the user. For example if the user inputs a bad case sentance it will make it normal:
what do yOu think? -> What do you think?
It checks for ./?/!. Have fun.
Original Author: Vitaly
Inputs
Bad case string
Returns
Proper case string
Code
Function Proper(Text As String)
Dim FirstLetter%, I%, BadFormat%, J%, Loc%, Sta%
Dim BreakL$, BreakR$
'------------------------
Text = LCase(Text)
FirstLetter = Asc(Mid(Text, 1, 1))
If FirstLetter >= 97 And FirstLetter <= 122 Then
Text = Right(Text, Len(Text) - 1)
Text = Chr(FirstLetter - 32) & Text
End If
For I = 1 To Len(Text) - 2
If Mid(Text, I, 1) = "." And Asc(Mid(Text, I + 2, 1)) >= 97 And Asc(Mid(Text, I + 2, 1)) <= 122 _
Then BadFormat = BadFormat + 1
If Mid(Text, I, 1) = "!" And Asc(Mid(Text, I + 2, 1)) >= 97 And Asc(Mid(Text, I + 2, 1)) <= 122 _
Then BadFormat = BadFormat + 1
If Mid(Text, I, 1) = "?" And Asc(Mid(Text, I + 2, 1)) >= 97 And Asc(Mid(Text, I + 2, 1)) <= 122 _
Then BadFormat = BadFormat + 1
Next I
Loc = 1
For J = 1 To BadFormat
Sta = 200
If InStr(Loc, Text, ".") <> 0 Then Sta = InStr(Loc, Text, ".")
If InStr(Loc, Text, "?") < Sta And InStr(Loc, Text, "?") <> 0 _
Then Sta = InStr(Loc, Text, "?")
If InStr(Loc, Text, "!") < Sta And InStr(Loc, Text, "!") <> 0 _
Then Sta = InStr(Loc, Text, "!")
For I = Sta To Len(Text)
If Asc(Mid(Text, I, 1)) >= 97 And Asc(Mid(Text, I, 1)) <= 122 Then
Loc = I + 1
FirstLetter = Asc(Mid(Text, I, 1))
BreakL = Left(Text, I - 1)
BreakR = Right(Text, Len(Text) - I)
Text = BreakL & Chr(FirstLetter - 32) & BreakR
Exit For
End If
Next I
Next J
Proper = Text
End Function
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.