Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Words spelled the same just looking different .

Posted on 2003-03-07
7
Medium Priority
?
149 Views
Last Modified: 2010-04-04
Hi All,

This is not homework. I need an efficient way to make this happen

I have a word ...... any of any two or more letters,  for instance 'Td'. It can be entered in one of 2 ways.
 
If the word begins with a capital letter, then the  revised word should begin with a lower case letter and have the same spelling.  User enters 'Td' in Edit1 and does a button click and in Edit2 shows  'td'
OR
if the word begins with a lower case letter then the word revised should begin with a capital letter and have the same spelling.  User enters 'td' in Edit1 and does a button click and in Edit2 shows  'Td'

Delphi3
0
Comment
Question by:delphi3
7 Comments
 
LVL 6

Accepted Solution

by:
zebada earned 200 total points
ID: 8093303
if ( Length(Edit1.Text)>1 ) then
begin
  if ( Edit1.Text[1] in ['A'..'Z'] ) then
    Edit2.Text := LowerCase(Edit1.Text[1])+Copy(Edit1.Text,2,MAXINT)
  else if ( Edit1.Text[1] in ['a'..'z'] ) then
    Edit2.Text := UpperCase(Edit1.Text[1])+Copy(Edit1.Text,2,MAXINT)
  else
    Edit2.Text := Edit1.Text;
end
else
  Edit2.Text := Edit1.Text;



0
 
LVL 6

Expert Comment

by:DaFox
ID: 8093676
Hi.

procedure TForm1.Button1Click(Sender: TObject);
var
  c: Char;
begin
  if (Edit1.Text <> '') then
  begin
    c := #0;
    // word starting with capital letter
    if Ord(Edit1.Text[1]) in [65..90] then
    begin
      c := Chr(Ord(Edit1.Text[1]) + 32);
    end;
    // word starting with small letter
    if Ord(Edit1.Text[1]) in [97..122] then
    begin
      c := Chr(Ord(Edit1.Text[1]) - 32);
    end;
    Edit2.Text := c + Copy(Edit1.Text, 2, Length(Edit1.Text) - 1);
  end;
end;

Markus
0
 
LVL 1

Expert Comment

by:KillerApp
ID: 8094152
Edit2.Text = Chr(Ord(Edit1.Text[1]) xor 32) + Copy(Edit2.Text,2,MAXINT);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:DaFox
ID: 8094194
KillerApp, not bad!!! ;-)
That's what I wanted to do with ascii/ord/chr, but forgot what I wanted to do with it when I open up my Delphi ;-)

Unfortunately in this case you got no security checks. That means e.g. $oft is getting oft and so on, if you'd do it my way, only letters get inverted.

->   Edit2.Text := Chr(Ord(Edit1.Text[1]) xor 32) + Copy(Edit1.Text, 2, Length(Edit1.Text) - 1);

Markus
0
 
LVL 1

Expert Comment

by:KillerApp
ID: 8094289
>Unfortunately in this case you got no security checks.


That is true but the question said "I have a word ...... any of any two or more letters", so my answer is still valid :P

A secure version

if Length(Edit1.Text)>0 AND (Edit1.Text[1] in ['a'..'z','A'..'Z']) then
  Edit2.Text := Chr(Ord(Edit1.Text[1]) xor 32) + Copy(Edit1.Text, 2, Length(Edit1.Text) - 1);
0
 
LVL 4

Author Comment

by:delphi3
ID: 8095541
Thanks to you all for responding.

KillerApp, the secure version that you wrote needed some brackets more()'s after if(.... ) AND (.....)then ... to make it work in my pascal.
My revision would be:  
if (Length(Edit1.Text)>0) AND (Edit1.Text[1] in ['a'..'z','A'..'Z']) then
 Edit2.Text := Chr(Ord(Edit1.Text[1]) xor 32) + Copy(Edit1.Text, 2, Length(Edit1.Text) - 1);


zebada was in with a workable solution first.

Thanks again to all.
Delphi3








0
 
LVL 1

Expert Comment

by:KillerApp
ID: 8097307
Yes you are right, my mistake. I am always doing that! (in C++ and VB  the brackets would not be needed).
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question