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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Proper capitalization of a name or company 1

Status
Not open for further replies.

gentforreal

Programmer
Oct 19, 2002
62
US
We deal with many files that have hypenated names such as King Oldsmobile-honda. I have seen but cant find again funtions or snippets to conver Oldsmobile-honda to Oldsmobile-Honda.

Does anyone know of a function or small program snippet I could use to convert these pesky hyphenated names?

Thanks!
Will
 
If you know there won't be any additional embedded
spaces in the string, the following expression
will work.

CHRTRAN(PROPER(CHRTRAN("Oldsmobile-honda","-"," "))," ","-")

Darrell

'We all must do the hard bits so when we get bit we know where to bite' :)
 
Unfortunately, after looking I found instances where there were additional spaces. As ex: King Honda-Accura. Sorry, I forgot to mention my problem was not knowing where in the string the hypen might be. For simple two word strings I had already found your solution to work fine.. its these others that has me stumped.
 
xword="Oldsmobile-honda"
xno=1
xnum =1
do while xno > 0
xno=at('-',xword,xnum)
if xno > 0
xword=substr(xword,1,xno)+upper(substr(xword,xno+1,1))+substr(xword,xno+2)
endif
xnum = xnum+1
enddo


 
Hi Will,
**********************************************************
SCAN
cStr = PROPER(myField)
nCount = 1
DO WHILE .t.
lnPos = AT("-",cStr, nCount)
IF lnPos > 0
cStr=LEFT(cStr,lnPos)+PROPER(SUBSTR(cStr,lnPos+1))
ELSE
EXIT
ENDIF
nCount = nCount+1
ENDDO
IF myField # cStr
REPLACE myField WITH cStr
ENDIF
ENDSCAN
**********************************************************
:)

ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
The following algorithm will work when embedded spaces
already exist.

Darrell

lcName = "John Mason's Oldsmobile-honda"

FOR i = 1 TO OCCURS(" ",lcName)
DIME laSpaces
laSpaces = AT(" ",lcName,i)
NEXT

lcName = CHRTRAN(PROPER(CHRTRAN(lcName,"-"," "))," ","-")

FOR i = 1 TO ALEN(laSpaces)
lcName = STUFF(lcName,laSpaces,1," ")
NEXT

? lcName && Voila!


'We all must do the hard bits so when we get bit we know where to bite' :)
 
Sorry...

Forgot '[ i ]' would change to italics...

lcName = "John Mason's Oldsmobile-honda"

FOR i = 1 TO OCCURS(" ",lcName)
DIME laSpaces( i )
laSpaces = AT(" ",lcName,i)
NEXT

lcName = CHRTRAN(PROPER(CHRTRAN(lcName,"-"," "))," ","-")

FOR i = 1 TO ALEN(laSpaces)
lcName = STUFF(lcName,laSpaces( i ),1," ")
NEXT

? lcName && Voila!


'We all must do the hard bits so when we get bit we know where to bite' :)
 
Not to beat a dead horse, but here is the
solution presented as a function. I've included
it in my repository of functions.

Thanks for the problem - it'll help me also.

Darrell

************************************************************
*-- Function: ProperNameWithHyphens
*-- Author: Darrell C. Greenhouse
*-- Last Upate:
*-- Created: 2003.05.17
*-- Description: Converts a string with embedded hyphen
* and spaces to all hyphenated name
* parts set to Proper case.
*-- Pass: Char: lcName
*-- Returns: Char: lcName
*-- Called by:
*-- Calls:
*-- Assumuptions:
*-- Notes:
*-- Todo: Modify to take an additional
*-- parameter to specify which chars
*-- to convert and rename the function
*-- to a generic name
*-- Revisions:
************************************************************
FUNCTION ProperNameWithHyphens(lcName)
LOCAL i
LOCAL ARRAY laSpaces( 1 )
FOR i = 1 TO OCCURS(" ",lcName)
DIME laSpaces( i )
laSpaces( i ) = AT(" ",lcName,i)
NEXT
lcName = CHRTRAN(PROPER(CHRTRAN(lcName,"-"," "))," ","-")
FOR i = 1 TO ALEN(laSpaces)
lcName= STUFF(lcName,laSpaces( i ),1," ")
NEXT
RETURN lcNameIn
ENDFUNC


'We all must do the hard bits so when we get bit we know where to bite' :)
 
Here is a routine I wrote in dBase to emulate FoxPro's PROPER() function, but adds a couple flexible options. First, it is set here to allow spaces and hypens as delimiters, but more could be added. Second, you can exclude certain words such as "a", "an", "and", "to", etc.

If you wish, you could pass in the settings as additional parameters, but here they are shown as part of the code.

Code:
FUNCTION cPROPER    && CONVERT ALPHA STRING INTO PROPER NAMES
PARAMETERS P_TEXT
PRIVATE X, C_TEXT

C_TEXT=P_TEXT

IF LEN(RTRIM(C_TEXT)) > 1

   C_TEXT=LOWER(C_TEXT)

   FOR X = 0 TO LEN(C_TEXT)-1
       * NOTE: ISALPHA() ONLY CHECKS ONE CHARACTER
       DO CASE
          CASE X=0 
               IF ISALPHA(SUBSTR(C_TEXT,X+1,1))  && BEGINNING
                  C_TEXT = STUFF(C_TEXT,X+1,1,UPPER(SUBSTR(C_TEXT,X+1,1)))
               ENDIF
          CASE .NOT. SUBSTR(C_TEXT,X,1) $ " -"
        * CASE SUBSTR(C_TEXT,X,1)<>&quot; &quot;
                  IF (X > 1 .AND. SUBSTR(C_TEXT,X-1,2) == &quot;Mc&quot;) .OR. ;
                     (X > 0 .AND. SUBSTR(C_TEXT,X,1) $ &quot;([{}])&quot;)
                     C_TEXT = STUFF(C_TEXT,X+1,1,UPPER(SUBSTR(C_TEXT,X+1,1)))
                  ENDIF
          CASE ISALPHA(SUBSTR(C_TEXT,X+1,1))
               IF .NOT. (SUBSTR(C_TEXT+&quot; &quot;  ,X,3) $ &quot; a &quot;   .OR. ;
                         SUBSTR(C_TEXT+&quot;  &quot; ,X,4) $ &quot; in is of or &quot;  .OR. ;
                         SUBSTR(C_TEXT+&quot;   &quot;,X,5) $ &quot; and the &quot; )
                       * OTHER POSSIBLES: at from to for by
                  C_TEXT = STUFF(C_TEXT,X+1,1,UPPER(SUBSTR(C_TEXT,X+1,1)))
               ENDIF
       ENDCASE
   NEXT
ENDIF
RETURN C_TEXT  && THIS IS RETURNED BY FUNCTION
 
as usual.... I tried to make it difficult..

Hey.. the strtran() function is all thats needed!!

Thanks to all!
 
gentforreal,

I'm glad you've found the solution. Could you tell me how you are using the strtran() function to address the problem you've outlined above? Just a snippet or quick explanation would do. At first I thought that you were perhaps using the strtran() function to replace some of the code posted above by darrellblackhawk, but your line &quot;...the strtran() function is all thats needed!!&quot; has me wondering if you have found a single line that works.

darrellblackhawk,

Yeah I ran into that
Code:
[I]
turned to italics thing once. Gagnon showed me the [ code][ /code] tags a little while back and I use them now...just passing it on in case you didn't know, if you already knew then ignore me. :)

Slighthaze = NULL
 
Yep... I knew.
I use '[i..j..k...]' as array iterators all of the
time, so I have to be careful on this forum.

Darrell

'We all must do the hard bits so when we get bit we know where to bite' :)
 
Hi: have been learning from this discussion. . .very good stuff. . .my compliments!

Been trying to get this to work:

PUBLIC cLname
cLname=dex.cLastname ??? &quot;McMillian&quot; , &quot;McCoy&quot; etc.

Field imput mask is &quot;proper&quot;
How can I get the &quot;M&quot; or &quot;C&quot; to be UPPER?

THX for any feedback.

Bill
 
darrellblackhawk

Forgot '[ i ]' would change to italics...

Just a suggestion, but in order to &quot;show&quot; something in between square brackets, either unselect the &quot;process TGML&quot; at the bottom of your post (which will ignore all TGML tags in that post) or you could also use the [&quot;ignore&quot;][&quot;/ignore&quot;] (without the quotation marks) tags before and after the area where you need to show the &quot;[&quot; .



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks for the tip Mike.


'We all must do the hard bits so when we get bit we know where to bite' :)
 
Sermac:

Although your problem is related, you should start
a new thread and possibly reference the thread that
piqued your interest. Otherwise, your request might
get lost in the rest of the posts of the related thread.

As to your problem, a modification of the solution I
provided will probably work. Unfortunately, I don't
have the time right now to explore it.

There are a number of functions out there that are
'McCoy' aware :), so I doubt you'll be without help
for long.

Darrell


'We all must do the hard bits so when we get bit we know where to bite' :)
 
I added a small snippet is all.....

replace all company with strtran(company,&quot;-&quot;, &quot; &quot;)

Viola, all dashes are gone.... Works every time.

Seems I am always missing the easy way.

Now I have to deal with how to identify if a field exists... Afield? or Ascan? sigh.
 
I thought you wanted to keep the hyphens.

As when a woman appends their husband's last name
onto the end of their own.

Anyway, the problem was fun!

btw use:

lnFieldCount = afields(laFields, cTableName|WorkArea#)

Note that the table referenced gets selected automatically
with the afields() command, so you may want to save
the current workarea

Darrell

'We all must do the hard bits so when we get bit we know where to bite' :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top