Welcome! Log In Create A New Profile

Advanced

Proper case a string

Posted by John Marrone 
John Marrone
Proper case a string
November 21, 2008 12:59PM
Hi
Does WD have a function to proper case a string. ie: "john marrone" to "John Marrone" or "JOHN MARRONE" to "John Marrone". I have looked in help but to no luck. Thanks for any help.
DarrenF
Re: Proper case a string
November 21, 2008 01:19PM
Hi,

I was hoping for this feature also.

You'll probably have to write something yourself.

Some of the other systems I've worked with (Alpha5) had this feature... but not WD :sneg:

Should be quite easy tho... shouldn't it? winking smiley
John Marrone
Re: Proper case a string
November 21, 2008 02:01PM
Here's the code...

PROCEDURE Proper(str is string)
LOCAL
	i is int
	str = NoSpace(str) 
	numChars is int = Length(str)
	chr, retStr is string
	lastSpc is boolean = True
	
	
	FOR i = 1 TO numChars
		chr = Middle(str,i,1)
		IF chr = " " THEN
		retStr += chr
			lastSpc = True
		ELSE
			IF lastSpc THEN
				retStr += Upper(chr)
				lastSpc = False
			ELSE
				retStr += Lower(chr)	
			END
		END
		
	END
	RESULT retStr
	
:-)
DerekT
Re: Proper case a string
November 24, 2008 05:26PM
John, Hi

Same idea, different code
Coincedentally I had recently changed mine as I read in the Help that Upper & Lower were only kept for backward compatability.
StringFormat is now preferred as it also handles UniCode characters.

PROCEDURE lpCase(pString is string)

lbIsSpace  is boolean = False
lcToCheck  is character
lcCaseRes  is string
lnSpaceCnt is int = StringCount(pString," ",IgnoreCase)  //Check for spaces in the source string
lnStrLen   is int = Length(pString)  //Number of characters to check
lsCaseSet  is string

IF lnSpaceCnt > 0 THEN
	FOR i = 1 TO lnStrLen  //Loop through all characters
	lcToCheck = Middle(pString,i,1)  //Set character to check
		SWITCH True
			CASE i = 1:
				lcCaseRes = StringFormat(lcToCheck,ccUpCase)  //Set 1st character to upper case
			OTHER CASE
				IF NOT lbIsSpace THEN  //Process lower case (including spaces)if lbIsSpace = False
					lcCaseRes = StringFormat(lcToCheck,ccLowCase)
				ELSE
					lcCaseRes = StringFormat(lcToCheck,ccUpCase)  //Set to upper case if lbIsSpace = True
					lbIsSpace = False 							  //then reset the "lbIsSpace" flag 
				END
				IF lcToCheck = " " THEN  //If the character just processed is a space
					lbIsSpace = True    //then set the "lbIsSpace" flag to True for next iteration
				END
				END
					lsCaseSet += lcCaseRes  //Concatinate the individual characters
				END
		pString = lsCaseSet  //Update the received parameter with the new string for return
END

Regards

DerekT
Chris L
Re: Proper case a string (in entry fields)
December 03, 2008 09:17AM
I have been asking for this feature, or something very similar at least, since version 5.5 and I cannot understand why PC Soft has failed to implement such a simple but important feature.

My particular hobby horse is something just a little different. I want to be able to select proper/title case as an entry mask. There are many masks which can be applied to entry fields but nowhere can one find that most useful mask, proper/title case.

Like others above, I ended up writing a piece of code to implement this. But it's annoying (and frustrating) to have to include this code with every application. It's even more annoying having to attach it to every entry field.

There's no mention of this coming in WD14. Maybe in 15?

Chris L
Melbourne, Oz

John Marrone
Re: Proper case a string (in entry fields)
December 03, 2008 10:49PM
Chris I totally agree with you. I was very surprised when I realized WD did not have this feature.
Art Bonds
Re: Proper case a string (in entry fields)
December 04, 2008 12:39AM
art bonds
john marrone
big al

All easy names that would lend themselves to CAP(string) the first letter.

But what happens with names like

reyes de la torre

where the de and la are not capped?
Jimbo
Re: Proper case a string (in entry fields)
December 04, 2008 10:07AM
Hi Chris,

just for a clarification: You yourself could not decide in all cases about which words to show a first character in upper or lower case. This is not an easy job even for a human being. But how should a piece of software do that? However, please keep in mind that more than 50% of the users of the English version of WinDev are not native English speakers, their software is in about hundred different languages. For myself, I dont care for 'proper case', because there's no such thing in German, Czech, Hungarian or Croatian.

If you could come up with a surefire method of proper case, there's no doubt that PC Soft could implement that. However, if you had such a method / decision tree, you could implement it yourself too. Or publish it here for common use.

Btw: What I have seen on the web as 'proper case' solutions are no solutions at all. They could be summarized into the simple rule: first put all characters of the string to lower case, after that put all characters after a space or punctuation character. Result:
Seattle, Usa: Camilla Parker-Bowles And Peter O'Toole Visit A Mcdonald'S.
'Usa', 'And' and 'A' are wrong in proper case, so, you could exclude these words. McDonald's is a special case .. but there are other cases in proper names too which aren't easy to handle. Definitely, you'd end up in a string with raw proper casing and possibly a bunch of errors. This isn't what PC Soft should supply ..

Kind regards,
Guenter




Edited 3 time(s). Last edit at 12/04/2008 10:31AM by Jimbo.
Merijn
Re: Proper case a string
December 04, 2008 10:31AM
What about this algorithm, I couldn't resist in writing a word orriented implementation:

sTmp, sOutput, sInput is string="merijn van der wijk"
iPiece is int
iMax is int = StringCount(NoSpace(sInput)," ") + 1
FOR iPiece=1 TO iMax
	sTmp=StringFormat(Lower(ExtractString(sInput,iPiece," ")))
	// only upper large words and allways the first word
	IF Length(sTmp) > 3 OR iPiece=1 THEN sTmp[ [1] ] =Upper(sTmp[ [1] ])
	sOutput+=sTmp + " "
END
sOutput=NoSpace(sOutput)

Merijn van der Wijk (MSG-i)

By the way, Dutch-speaking Windev, Windev-Mobile and/or Webdev programmers [[5]]
interested in a new career are invited to contact us: www.msgnl.com/vacatures.asp



Edited 1 time(s). Last edit at 12/04/2008 10:33AM by Merijn.
Jimbo
Re: Proper case a string
December 04, 2008 10:38AM
Hi Merijn,

please, test the following sentences:

"old mcdonald's and o'leary visit a farm of camilla parker-bowles in the usa"
"a very old man is number one!"

just to prove, that 'proper case' is non-trivial stuff.

Kind regards,
Guenter
Merijn
Re: Proper case a string
December 04, 2008 10:51AM
Guenter,

You have proven that this is very tricky to implement for sentences and exceptional names.
However the algorithms posted in this thread are all fearly acceptable for e.g. address and name fields. And for this usage only a W-Language function or stringformat optional could be provided to us.


Art Bonds
Re: Proper case a string
December 04, 2008 06:43PM
True. However, your customers will occasionally enter "exceptional" names and addresses in those fields (especially in places like California with a heavy Mexican influence), and the first time your program handles it incorrectly you will get a bug report. Your program does not work properly.

Then you get to spend time explaining to your customer how difficult it is to correctly implement this sort of functionality, and during this explanation all your customer will be thinking is what an idiot programmer you are because you cannot "implement such a simple but important feature" (to borrow a few words...).

All that just to avoid having some typist avoid having to push down a SHIFT key every now and then like they were trained to do in the first weeks of any basic typing class.

Right?

I'm with Guenter on this one...


John Marrone
Re: Proper case a string
December 04, 2008 09:20PM
Hi Art
Good to see your name again. I covert a string I read from a data file and I convert an all upper case string to a proper string. And nothing funny is ever in the string in my case. Also Art do you know if PCSoft is ever going to come out with a 32 bit IDE, sort of like .net. With tabs and so forth. I haven't upgraded since version 11 and I probably won't until they upgrade the IDE. Good to see your still around. My work have me using .net. So only work with WD on my own projects which is going slow. I have this sickness called golf. I cannot shake it. Good to see you around. Take care and have a good holiday season.

Art Bonds
Re: Proper case a string
December 05, 2008 12:45AM
Hi John,

I guess in many cases here in the US we'd get no funny business doing these types of conversions. But WD is not limited to the States,so PCS has to do what is best for the international community, unlike Clarion which is more US centric and has such a function built in..

Can't help on your other question, no idea what PCSofts plans are.
Chris L
Re: Proper case a string (in entry fields)
December 14, 2008 05:35AM
[Just noticed that this thread has continued on quite a bit since my previous contribution.]

Guenter

Sorry, but here I must take issue with you.

Just because a general condition does not apply in every single case should not prevent a general implementation.

You also seem to miss the point about title case, also called proper case. I can see no situation where I would want to apply this to a whole phrase or sentence. Forget the term 'title' case if this is confusing (the majority of English-language style guides now argue against the old practice of capitalising all major words in titles). Call it 'proper' case, the capitalisation of the first letter of names, places, addresses.

Sure there are names with irregular capitalisation. The most common occurrences in English names are of course the McDonnells and the O'Briens and such like. And we do have the occasional John de la Coursier or Richard van Otterdyk and so on.

But the vast majority of names and addresses in the English-speaking world, probably 95% plus, fit in with standard title case.

It is far easier to adjust the occasional entry of "non-standard" names such as those above than to have to manipulate the vastly greater number of standard names which a user enters without capitalisation or with mixed capitalisation because they have the Caps Lock on or have pressed the Shift key at the wrong time.

You suggest that proper case has no place in non-English languages. How then do you explain your own name Guenter Predl (proper case), your company Systemhaus Predl Informationstechnologie-GesmbH (proper case with one adjustment), and your address
Wehlistrasse 51 / 2 / 20, A-1200 Wien (all proper case)?

For further proof, just look back at the names of the contributors to this forum. Which of these do not conform entirely to proper case, ie capital first name, capital last name? Scrolling back through several hundred entries, I can only find one regular contributor: Piet van Z. If you go back through the thousands of entries on this forum you will also find one other 'van' and a 'de'. So even though you assert that more than 50% of the users of English-language WD are non native English speakers, 99% of their names conform to proper case without adjustment!

You also seem to suggest that because there are exceptions to a rule, because one cannot provide an algorithm which applies in every single instance (even 'Mac' can be problematic in English: some people are MacDonnell, some are Macdonnell), then there should be no accommodation for the 95%, perhaps 99% plus, majority.

My English-language version of WinDev has an entry mask for phone numbers. If I choose this, I get (+33)1.23.45.67.89. Huh? How many users in this forum can use this mask? (Yes, I realise it's for French phone numbers but there's also a separate entry mask for French phone numbers!)

If PC Soft are happy enough to include this mask, along with a mask for 'INSEE number' (along with 'INSEE number + key') -- what on earth is an 'INSEE number'?, and also obscure masks like 'Letter then Letter(CAPS)/Digit'), why can't they include a simple proper case? How hard can it be?

It is possible to create one's own custom mask but this option is very limited and are really only useful for a field with a very regulated format such as postal codes. Text options are limited and certainly it does not cater for something like proper case.

So I ask yet again - why can't PC Soft implement a simple proper case mask?

Chris L
Melbourne, Oz


Jimbo
Re: Proper case a string (in entry fields)
December 14, 2008 11:12AM
Quote
Chris L
[Just noticed that this thread has continued on quite a bit since my previous contribution.]

Guenter

Sorry, but here I must take issue with you.

Just because a general condition does not apply in every single case should not prevent a general implementation.

You also seem to miss the point about title case, also called proper case. I can see no situation where I would want to apply this to a whole phrase or sentence. Forget the term 'title' case if this is confusing (the majority of English-language style guides now argue against the old practice of capitalising all major words in titles). Call it 'proper' case, the capitalisation of the first letter of names, places, addresses.

Sure there are names with irregular capitalisation. The most common occurrences in English names are of course the McDonnells and the O'Briens and such like. And we do have the occasional John de la Coursier or Richard van Otterdyk and so on.

But the vast majority of names and addresses in the English-speaking world, probably 95% plus, fit in with standard title case.

It is far easier to adjust the occasional entry of "non-standard" names such as those above than to have to manipulate the vastly greater number of standard names which a user enters without capitalisation or with mixed capitalisation because they have the Caps Lock on or have pressed the Shift key at the wrong time.

You suggest that proper case has no place in non-English languages. How then do you explain your own name Guenter Predl (proper case), your company Systemhaus Predl Informationstechnologie-GesmbH (proper case with one adjustment), and your address
Wehlistrasse 51 / 2 / 20, A-1200 Wien (all proper case)?

For further proof, just look back at the names of the contributors to this forum. Which of these do not conform entirely to proper case, ie capital first name, capital last name? Scrolling back through several hundred entries, I can only find one regular contributor: Piet van Z. If you go back through the thousands of entries on this forum you will also find one other 'van' and a 'de'. So even though you assert that more than 50% of the users of English-language WD are non native English speakers, 99% of their names conform to proper case without adjustment!

You also seem to suggest that because there are exceptions to a rule, because one cannot provide an algorithm which applies in every single instance (even 'Mac' can be problematic in English: some people are MacDonnell, some are Macdonnell), then there should be no accommodation for the 95%, perhaps 99% plus, majority.

My English-language version of WinDev has an entry mask for phone numbers. If I choose this, I get (+33)1.23.45.67.89. Huh? How many users in this forum can use this mask? (Yes, I realise it's for French phone numbers but there's also a separate entry mask for French phone numbers!)

If PC Soft are happy enough to include this mask, along with a mask for 'INSEE number' (along with 'INSEE number + key') -- what on earth is an 'INSEE number'?, and also obscure masks like 'Letter then Letter(CAPS)/Digit'), why can't they include a simple proper case? How hard can it be?

It is possible to create one's own custom mask but this option is very limited and are really only useful for a field with a very regulated format such as postal codes. Text options are limited and certainly it does not cater for something like proper case.

So I ask yet again - why can't PC Soft implement a simple proper case mask?

Chris L
Melbourne, Oz


Hi Chris,

thank you for adding more insight to the issue !

Sure enough, all the way long, I took 'title case' for 'proper case'. As I can see, these may not be identical ..

German language / print: There are lots of words which have to start with an uppercase letter! The first character of a sentence, proper names, all nouns and all words used like a noun have to start with an uppercase character, no way out. In German, titles aka headlines in newspapers do not follow a separate rule as they do in English. The headline 'Premierminister Gordon Brown besucht Sidney!' equals to 'Mr. Brown Visits Sidney!'. There's virtually no difference of the German sentence in a headline to its appearance in the text body of a document. But in English, there is.

My name / address consists of proper names and nouns and therefore it seems to you to be a fine example of 'proper case'. It is not. Because 'Predl Guenter', 'Wehlistrasse' and 'Wien' altogether are proper names, their first characters have to be capitalized under all circumstances. However, the 'van' in 'Teun van Unen' would be an exception to the rule. I concede that a button with a simple 'proper case' algorithm (plus consideration to some frequent exceptions) would serve well to represent address fields in German. But not for any headline!

Mask for phone numbers. This ridiculous mask is a curse since WinDev 5.5 and maybe, it's for Canadian phone numbers. It's true, in some countries, not only in France, they put dots after every two figures in order to enhance readability of the number. The French spelling of numbers calls for cutting into parts of two figures ;-) otherwise comprehension errors would be a daily pain. Austrian and German phone numbers definitely do not fit a mask. US-numbers do and could be handled by a mask therefore. Whatever, if you know that Australian phone numbers do follow a rule, you could write your own mask & checking algorithm. There's the ..InputMask property.

INSEE. Propably not spoken like English-speaking people would do - both 'E's are spoken like the 'e' in 'bend'. Difficult. It's the French National Institute for Statistics and Economic Studies. [www.insee.fr]

Quote

So I ask yet again - why can't PC Soft implement a simple proper case mask?

Admitted, because Europeans (Swiss, Germans, Austrians and quite some French, Belgians, Polish people, Czechs etc.) are special folks. We believe in 2 x 2 = 4. Always. No exceptions to the rule. A result of the 'Aufklaerung' ( [en.wikipedia.org] ) We hate to even think of an algorithm that could fail once in a lifetime. 'Proper case' is an algorithm that can fail once a day at a given customer site. Beware!

I suggest that you write your own algorithm and supply your warnings about possible failure to your customer. You could publish your solution in <a target=new href="[forum.mysnip.de] Solutions</b></u></a>. This would enable others to add their additions, suggestions and / or to develop 'proper case' for other languages - and publish their algorithms.

Thank you!

Kind regards,
Guenter


Chris L
Re: Proper case a string (in entry fields)
December 14, 2008 01:27PM
Thanks, Guenter.

I suspect we might be going round in circles here.

First of all, let's forget about headlines, book titles and the like. I agree the term 'title case' is now outmoded; as I said before, the use of this case in titles, headlines, etc has been abandoned in many/most English-language publications. English-language style guides for Australian, British and American English nearly all now recommend standard capitalisation, ie proper names only, for general use in titles, headlines, etc.

My interest is in a general mask for names and addresses using proper names which as an almost universal rule have their first characters capitalised. (So the term 'proper' case is more appropriate.) That's all I'm after.

Quote

My name / address consists of proper names and nouns and therefore it seems to you to be a fine example of 'proper case'. It is not. Because 'Predl Guenter', 'Wehlistrasse' and 'Wien' altogether are proper names, their first characters have to be capitalized under all circumstances.

I don't know what you call this in German but in English, the examples you have quoted ARE very definitely examples of 'proper case'.

Upper case: GUENTER PREDL
Lower case: guenter predl
Proper case: Guenter Predl

Just Google this and you will find millions of references to this term.

Other computer languages and applications recognise this and have done so for many many years. Microsoft Excel has the PROPER() function to convert 'GEORGE W. BUSH' to 'George W. Bush' (to quote an example form one Excel guide). It will also convert 'gordon brown' to 'Gordon Brown'. It is most useful for fixing up input typos such as 'gORDON bROWN' (because CAPS LOCK is on) or 'GorDOn brOwn' (because of clumsy or rapid typing).

I seem to remember that even Clarion, now increasingly ever more primitive compared with WinDev, had this capacity many years ago. (From memory, you had a choice of 'Upper case', 'Lower case' and 'Capitalize' or something similar.)

Quote

I suggest that you write your own algorithm and supply your warnings about possible failure to your customer.

In the past, I have written a function to convert user input into proper case but this then has to be attached to every entry field where names and addresses are entered. Very cumbersome, very tedious and something which should be quite unnecessary.

As for the ..InputMask property, that's as useless as the standard entry mask (because it's the same as the standard mask on an entry field).

Perhaps all your data entry fields for names and addresses are always upper case. That's one way of solving the problem. It's not a solution I like, especially when names and addresses are to be printed out on reports and letters.

Perhaps your users are all very careful, competent and painstaking people who never make a mistake when inputting names and addresses. Never mix upper and lower case. Never put in a name all in capitals or all in lower case. Never forget to turn off the CAPS LOCK key. Never hold the SHIFT key down too long. (There's a school of thought which suggests that if users aren't making mistakes, they aren't working fast enough!)

But the users I've dealt with over the years have been prone to all these errors. If they see the error straight away, they interrupt their smooth workflow to go back and correct the error. Otherwise it goes into the system to be picked up some time later when it embarrassingly appears on a form letter.

I prefer to use a function so that they do not have to worry about this. Once in every few hundred names they'll have to make a correction when a McDonald pops up but that's just a fraction of the corrections they would have to make without an input mask.

My point remains: other languages, other applications do it. Why not WinDev? There's simply no excuse not to include this mask.


Chris


PS Lest you think I'm totally Anglo-centric, I would like to point out that although I am a naturalised Australian and have lived here most of my life, I was born in the UK (actually on an island off the south coast) and my father was Polish! I've tried to learn Polish at various times and certainly picked up the basics, enough to see both the regularity and the complexity (seven different cases of nouns and adjectives -- nominative, accusative, dative, locative, etc, five genders, plus singular and plural). I studied French right through school and have maintained some reading comprehension with this language which has proved useful with WinDev. At university, I studied German, mainly from a scientific perspective. I also have nodding acquaintanceships with Russian and Italian and even studied Esperanto in my younger days! (Before anyone tries to communicate with me in anything other than English, I should make it clear that I am not fluent in anything other than English!)

Thanks for the explanation of 'INSEE'. Further exploration in the WD Help file produced further information: that this is like a national identity number for French citizens.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: