Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Input into Sentence Case??? 2

Status
Not open for further replies.

Shokoya

IS-IT--Management
Aug 4, 2003
81
GB
Hi Guys,

Trying to take a memo string input and convert it into Sentence Case i.e. the dog is black. the cat is brown. > The dog is black. The cat is brown.

Looked through the archives, but can't seem to find anything...any suggestions??

[cheers]
 
Thanks Ken

Had already looked in there and the only thing I could find which nearly did waht i require is vbPropercase.

Only problem with this is that it converts the 1st letter of each word in the string to UpperCase i.e. The Dog Is Black. The Cat Is Brown. as opposed to converting just the 1st letter of the sentence, and after full stop e.g The dog is black. The cat is brown.

[cheers]
 
Hi

Sorry, yes you are quite right, I had it firmly fixed in my mind there was a vbSentanceCase option, must have dreamt it !

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Here's some code I wrote to tidy up names from an input file. You're welcome to use it though you may need to modify if you are using a full memo field - I can't remember if string is limited to 256 bytes?

[green]Public Function Title_Case(Name As String) As String
' Change Name to Title Case. Include Mac, Mc, O', de

Dim L As Integer
Dim C As String
Dim I As Integer

Dim Word() As String
Dim TempStr As String
' Start by trimming spaces, removing multiple spaces and setting all to lower case
Name = LCase(Trim(Name))
Do
If InStr(Name, " ") = 0 Then Exit Do
Name = Replace(Name, " ", " ")
Loop

' Split Name into an array (one word per element) after replace ,' and - with space
' Need to keep Name in order to put spaces or commas full stops back at the end
TempStr = Name

TempStr = Replace(TempStr, ",", " ")
TempStr = Replace(TempStr, "-", " ")
TempStr = Replace(TempStr, "'", " ")
TempStr = Replace(TempStr, ".", " ")

Word = Split(TempStr, " ")
For I = 0 To UBound(Word)
Word(I) = UCase(Left(Word(I), 1)) & Mid(Word(I), 2, Len(Word(I)))
Word(I) = PreNames(Word(I))
Next I
Title_Case = ""
For I = 0 To UBound(Word) - 1
Title_Case = Title_Case & Word(I) & " "
Next I

Title_Case = Title_Case & Word(UBound(Word))
For L = 1 To Len(Name)
If Asc(Mid(Name, L, 1)) < 65 Then
Title_Case = Left(Title_Case, L - 1) & Mid(Name, L, 1) & Mid(Title_Case, L + 1, Len(Title_Case) - L)
End If
Next L

End Function

Public Function PreNames(Text As String) As String
PreNames = Text
If Left(Text, 3) = "Mac" Then
PreNames = Left(Text, 3) & UCase(Mid(Text, 4, 1)) & Mid(Text, 5, Len(Text) - 4)
End If
If Left(Text, 2) = "Mc" Then
PreNames = Left(Text, 2) & UCase(Mid(Text, 3, 1)) & Mid(Text, 4, Len(Text) - 3)
End If
If Left(Text, 2) = "O'" Then
PreNames = Left(Text, 2) & UCase(Mid(Text, 3, 1)) & Mid(Text, 4, Len(Text) - 3)
End If
End Function [/green]

Simon Rouse

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top