1. Computing

in Delphi Challenges ::

According to Delphi Naming Conventions local variables and method names should use camel casing.

Camel casing is a convention for capitalizing identifiers where the first letter in the identifier and the first letter of each subsequent concatenated word are capitalized. Examples inculde: MySuperWebSite, DelphiSoureCode, FirstYearSalary, etc.

Your challenge is to code a custom Delphi function with the following signature:

function UnCamelCase(const camel: string) : string;

UnCamelCase takes one parameter: camel that is a string value. The function should return a string that has been "de-camel-cased" - where "words" are separated by a space character.

Read the full article to learn how to join this Delphi Challenge: Create an Algorithm To Un-Camel-Case a CamelCase String


October 19, 2009 at 7:04 am
(1) Michael Rockett says:

This challenge can prove to be slightly difficult. However, it is fun. You should give it a try! :)

My solution was very simple, and I found a few glitches in it. Nevertheless, it works. :)

October 21, 2009 at 3:32 pm
(2) delphigeist says:

this contest(from what I see) is very simple to accomplish,

var i : integer;
words : array of string; // array where we keep the words
indexes : array of integer; // indexes of first uppercase char
for i := 1 to Length(theString) do
if theString[i] in ['A'..'Z'] then begin
// calling setLength so many times is bad for performance, find a better way!
setLength(words, Length(words) +1);
setLength(indexes, Length(indexes) +1);
indexes[i] := i;
if i > 0 then // this means that this is at least the second word
word[i] := Copy(theString, indexes[i-1], i -1);
// and so on, I will not show you the full implementation, this is just an idea

October 22, 2009 at 12:03 pm
(3) Claude says:

Code it up and submit it by e-mail if you think you have a good solution!

December 29, 2009 at 4:42 pm
(4) Diemesse says:

Zarko awarded everyone points. Here was my submission:

Function UnCamelCase(const camel : string) : string;
Var i: integer;
result := camel;
for i := length(result) downto 2 do
if (result[i-1] in ['a'..'z']) and (result[i] in ['A'..'Z']) then
insert(‘ ‘,result,i);

This was pretty compact code, but there were others who compacted even better, but the one who won the speed challenge was not concerned with compactness as much as speed. I was surprised at how fast his code ran.

You can download the results from everyone and compare them. Great stuff for learning, I liked Jim Murtha’s test for caps.


Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

©2014 About.com. All rights reserved.