Board index » delphi » Uppercase of first character

Uppercase of first character

How do I make the first character in an edit-box
uppercase..

I figured I could do something like
EditBox.Text[1] := UpCase(EditBox.Text[1]) +
Copy(EditBox.Text,2,Length(EditBox));

but it doesnt work for some reason :) ..

Please, respond via email!

 

Re:Uppercase of first character


Daniel <surr...@academy.bastad.se>,

Quote
>How do I make the first character in an edit-box
>uppercase..

>I figured I could do something like
>EditBox.Text[1] := UpCase(EditBox.Text[1]) +
>Copy(EditBox.Text,2,Length(EditBox));

>but it doesnt work for some reason :) ..

  You'll have to first make a copy the string:

  St := EditBox.Text;
  St[1] := UpCase (St[1]);
  EditBox.Text := St;

This is because the Text property of the EditBox is not an actual string
but instead a property that _points_to_ a string.  So you can't modify it
directly.

Good Luck,

-Ed Salgado
 Eminent Domain Software

Re:Uppercase of first character


Quote
Daniel Sundin/BADA <surr...@academy.bastad.se> wrote:
>How do I make the first character in an edit-box
>uppercase..
>I figured I could do something like
>EditBox.Text[1] := UpCase(EditBox.Text[1]) +
>Copy(EditBox.Text,2,Length(EditBox));
>but it doesnt work for some reason :) ..
>Please, respond via email!

Try the following:

procedure TForm1.Edit1Exit(Sender: TObject);
Var
EditStr : String;
begin
  EditStr := Edit1.text;
  EditStr[1] := UpCase(EditStr[1]);
  Edit1.Text := EditStr;
end;

Vito

Re:Uppercase of first character


Quote
>How do I make the first character in an edit-box
>uppercase..
>I figured I could do something like
>EditBox.Text[1] := UpCase(EditBox.Text[1]) +
>Copy(EditBox.Text,2,Length(EditBox));
>but it doesnt work for some reason :) ..

Of course it would not work.. But you got the right idea.

edit.text := uppercase(edit.text[1]) +
             Copy(edit.text,2,Length(edit.text));

Sandra Kim

SSDS INC.

Re:Uppercase of first character


Quote
Ed Salgado (easal...@icsi.net) wrote:

: Daniel <surr...@academy.bastad.se>,

: >How do I make the first character in an edit-box
: >uppercase..
: >
: >I figured I could do something like
: >EditBox.Text[1] := UpCase(EditBox.Text[1]) +
: >Copy(EditBox.Text,2,Length(EditBox));
: >
: >but it doesnt work for some reason :) ..

:   You'll have to first make a copy the string:

:   St := EditBox.Text;
:   St[1] := UpCase (St[1]);
:   EditBox.Text := St;

: This is because the Text property of the EditBox is not an actual string
: but instead a property that _points_to_ a string.  So you can't modify it
: directly.

: Good Luck,

: -Ed Salgado
:  Eminent Domain Software

Well actually you can, the following works fine:

  Edit1.Text := UpperCase(Copy(Edit1.Text,1,1)) + Copy(Edit1.Text,2,42);
  Edit1.SelStart := Length(Edit1.Text); (* Move cursor to EOL *)

   /Johan..!

Re:Uppercase of first character


Daniel <surr...@academy.bastad.se>,

Quote
>How do I make the first character in an edit-box
>uppercase..

Just a note on style:

If you intend on doing this to transparently capitalize english names,
what about cases like "O'Brien", or "d'Arcy", or "Smith-Jones",
or "MacDonald", or "von Trapp", or "van der Bergen" ?

Ie, names with apostraphes, or hyphens, or of Scottish, French, German,
whatever descent?

The same can apply not only to people's surnames, but to street
addresses, or locations.

Aaron Wigley

Re:Uppercase of first character


Quote
Daniel Sundin/BADA <surr...@academy.bastad.se> wrote:
>How do I make the first character in an edit-box
>uppercase..
>I figured I could do something like
>EditBox.Text[1] := UpCase(EditBox.Text[1]) +

             ^^^--<<remove
Quote
>Copy(EditBox.Text,2,Length(EditBox));

                     Length(EditBox.Text)-1);

Quote
>but it doesnt work for some reason :) ..
>Please, respond via email!

You were very close. The following works, putting
'before' => 'after' text in the form caption:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Caption:= '''' + Edit1.Text +''' => ''';
  if Length(Edit1.Text)>0 then begin
    Edit1.Text := UpCase(Edit1.Text[1]) +
      Copy(Edit1.Text,2,Length(Edit1.Text)-1);
  end;
  Caption:= Caption+Edit1.Text+'''';
end;

Regards,
Bengt Richter

Other Threads