String manipulation

  • Thread starter Thread starter Jamenson
  • Start date Start date
J

Jamenson

Hi everyone in group!

I have a textbox in which people type customer names. So, people
are typing like: "JESUS OF NAZARETH". I would like them to type
"Jesus of Nazareth" acording to the standard language rules, not
"Jesus Of Nazareth" ("O" capitalized) like StrConv does.


Any help appreciated.


Jamenson Ferreira Espindula.
 
Try using Access's StrConv function. You could put the following code in the
LostFocus event of the textbox. — Ken

me.textbox1 = StrConv(me.textbox1, vbProperCase)
 
The OP stated that he didn't want it formatted like StrConv() formats it.

Parsing and formatting names like this is always a hairball, because there
are so many variations, and basically you have to check for each one and
format accordingly. The following will check the name for the word "of" with
a space before and after it, and format it accordingly, but how many other
variations are you going to have to check for?

If InStr(OldName, " of ") > 0 Then
CorrectedName = StrConv(Left(OldName, InStr(OldName, " of ")), vbProperCase)

& "of" & StrConv(Right(OldName, InStrRev(OldName, " ")), vbProperCase)
End If

This will convert "JESUS OF NAZARETH". to "Jesus of Nazareth"

You could use the same general logic for other variations.

also

?Replace(strconv("JESUS OF NAZARETH",vbProperCase),"Of","of")
Jesus of Nazareth

?Replace(Replace(strconv("JESUS OF THE
NAZARETH",vbProperCase),"Of","of"),"The","the")
Jesus of the Nazareth
 
Michael Gramelspacher said:
also

?Replace(strconv("JESUS OF NAZARETH",vbProperCase),"Of","of")
Jesus of Nazareth

?Replace(Replace(strconv("JESUS OF THE
NAZARETH",vbProperCase),"Of","of"),"The","the")
Jesus of the Nazareth

Of course, you need to be careful when using Replace.

?Replace(Replace(strconv("JESUS OF THE THEOCRATIC
CHURCH",vbProperCase),"Of","of"),"The","the")

will produce

Jesus of the theocratic Church

Safer to put extra spaces in there:

?Replace(Replace(strconv("JESUS OF THE THEOCRATIC
CHURCH",vbProperCase)," Of "," of ")," The "," the ")
Jesus of the Theocratic Church
 
Of course, you need to be careful when using Replace.

?Replace(Replace(strconv("JESUS OF THE THEOCRATIC
CHURCH",vbProperCase),"Of","of"),"The","the")

will produce

Jesus of the theocratic Church

Safer to put extra spaces in there:

?Replace(Replace(strconv("JESUS OF THE THEOCRATIC
CHURCH",vbProperCase)," Of "," of ")," The "," the ")
Jesus of the Theocratic Church


Right you are! Nice to know there is someone watching over me to not allow me
to stray too afar.
 
OK, Thank all of you very much boys!

I will study and implement the solutions. After that, I will
feedback you.

Thank you!

Jamenson Ferreira Espindula.
 
Back
Top