mfrost03
asked on
Converting string to all upper case
I need to make sure that a user input is in all upper case for a form I am creating. How can I ether force the input as upper case or convert a string value into all upper case.
Thanks in advance
Mike
Thanks in advance
Mike
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
TEdit also TDBEdit has a CharCase-Property
just set it to ecUpperCase
meikl ;-)
just set it to ecUpperCase
meikl ;-)
Okay, if pjenglund already mentioned that I'll provide a way for my second suggestion. ;-)
procedure TForm1.Edit1KeyPress(Sende r: TObject; var Key: Char);
begin
// allow backspace and capital letters
if not (Key in [#8, #65..#90]) then Key := #0;
end;
Markus
procedure TForm1.Edit1KeyPress(Sende
begin
// allow backspace and capital letters
if not (Key in [#8, #65..#90]) then Key := #0;
end;
Markus
> TEdit also TDBEdit has a CharCase-Property
Yep;
procedure TForm1.Edit1KeyPress(Sende r: TObject; var Key: Char);
begin
if (Key in [#97..#122]) then Key := Char(Ord(Key) - 32);
end;
Just kidding.
If you're using a TEdit set CharCase to UpperCase and that's it. I forgot about that, sorry...
Markus
Yep;
procedure TForm1.Edit1KeyPress(Sende
begin
if (Key in [#97..#122]) then Key := Char(Ord(Key) - 32);
end;
Just kidding.
If you're using a TEdit set CharCase to UpperCase and that's it. I forgot about that, sorry...
Markus
ASKER
Thanks! Both answers are correct, but this allows me to control when the test is in uppercase or when it is in Normal input.
Just for Kicks I was also trying this to do a case update on each character in the string.
var
Cap: String;
i: Integer;
Begin
cap1 := Edit1.Text;
for i := 1 to Length(cap1) do
cap1[i] := UpCase(cap1[i]);
Edit1.Text := cap1;
End;
Thanks A Bunch!
Just for Kicks I was also trying this to do a case update on each character in the string.
var
Cap: String;
i: Integer;
Begin
cap1 := Edit1.Text;
for i := 1 to Length(cap1) do
cap1[i] := UpCase(cap1[i]);
Edit1.Text := cap1;
End;
Thanks A Bunch!
Use UpperCase() to convert the string after the user input or use the OnKeyDown/Press event to force the user to input capital letters.
Markus