What's wrong with this code to un-camel-case a string?
Posted
by omair iqbal
on Stack Overflow
See other posts from Stack Overflow
or by omair iqbal
Published on 2010-05-28T17:42:39Z
Indexed on
2010/05/28
17:51 UTC
Read the original article
Hit count: 301
Here is my attempt to solve the About.com Delphi challenge to un-camel-case a string.
unit challenge1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
check = 65..90;
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
var s1,s2 :string;
int : integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
checks : set of check;
begin
s1 := edit1.Text;
for i := 1 to 20 do
begin
int :=ord(s1[i]) ;
if int in checks then
insert(' ',s1,i-1);
end;
showmessage(s1);
end;
end.
check
is a set that contains capital letters so basically whenever a capital letter is encountered the insert function adds space before its encountered (inside the s1
string), but my code does nothing. ShowMessage
just shows text as it was entered in Edit1
. What have I done wrong?
© Stack Overflow or respective owner