Home > Back-end >  How to use the case to determine the string?
How to use the case to determine the string?

Time:10-12

Have such a corresponding relation between
EGY Egypt CHN China
IRL Ireland TWN Taiwan
AUS Australia GBR British
BRA Brazil ESP Spanish
POL Poland HKG Hong Kong
The SGP DNK Denmark Singapore
RUS Russia JPN Japan
PHL THA the Philippines Thailand
Cuba, CUB USA
NLD Dutch NGA Nigeria
ROM Romania KOR Korea
MYS Malaysia CAN Canada
FRA tex-mex Mexico France
CHE PRK, Switzerland, Korea
DEU Germany NZL New Zealand
ITA Italy MAC macau
AFG Afghanistan AGR Argentina

Enter a country code (CHN), returns (such as China) in Chinese, now I can only use if then, wanted to see if there is no player is more simple and convenient way to

CodePudding user response:

If the code is a String type, then the CHN can be seen as' CHN '# 0, take its first address as an Integer, under the x86 systems can be as a $004 e4843,


Procedure Test.
Var
Str1: AnsiString;
The begin
Str1:='CHN';
Case PInteger (PAnsiChar (str1)) ^ of
$004 e4843: ShowMessage (' China ');
The else
ShowMessage (' don't know ');
end;
end;

CodePudding user response:

For the String (especially AnsiString here) or a separate, not can not, only need to consider the possibility of memory access of crossing the line, so you need to have a precondition to determine whether memory can effectively,
For example:
Procedure Test.
Var
Str1: AnsiString;
The begin
Str1:='CHN=China';
Case PInteger (PAnsiChar (str1)) ^ of
$004 e4843: ShowMessage (' China ');
The else
ShowMessage (' don't know ');
end;
end;

CodePudding user response:

For the String (especially AnsiString here) or a separate, not can not, only need to consider the possibility of memory access of crossing the line, so you need to have a precondition to determine whether memory can effectively,
For example:
Procedure Test.
Var
Str1: AnsiString;
The begin
Str1:='CHN=China';
Case PInteger (PAnsiChar (str1)) ^ and $00 FFFFFF of
$004 e4843: ShowMessage (' China ');
The else
ShowMessage (' don't know ');
end;
end;

CodePudding user response:

To establish a two-dimensional table, a column is a code, make a list of Chinese name is countries;
Actually the principle principle is the same as the supermarket cashier system reads the bar code of goods!!!!!!
Supermarkets replace manpower input number with barcode gun, by bar code query goods record, read records of corresponding field in the future!
Give you advice is so kind!

CodePudding user response:

Available HashTable, key/value pair

CodePudding user response:

Find a related web page

Since the Delphi HashTable, used to manage key/value pair
http://blog.sina.com.cn/s/blog_59cb8a930100bvt7.html

CodePudding user response:

, I used to String directly use if then,
See the first time here, with Chinese name

CodePudding user response:

Use RTTI characteristics, HashTable, TStringList will do

EGY=Egypt
CHN=
China

CodePudding user response:

This apparent should build the mapping table to deal with

CodePudding user response:

If the data is mostly there is no need to use a HASH
Data of small words with two dimensional array

CodePudding user response:

The
reference 6th floor response:
found a related web page

Since the Delphi HashTable, used to manage key/value pair
http://blog.sina.com.cn/s/blog_59cb8a930100bvt7.html

HashTable can have good extension, but at this very specific requirements apply to you, calculate the Hash and Hash value in matching (Hash value is to be repeated) also needs a lot of consumption, is likely to be less than even the if condition, because inside the Hash found after still needs the if condition, just save the amount of code, look better,

CodePudding user response:

Enumerated types, every brother,

Type
TCountryCodes=(CHN, BRA, DEU, RUS);

The function GetCountryName (const CountryCode: TCountryCodes) : string;
Const
CountryNames: an array of string=[TCountryCodes] (' China 'and' Brazil ', 'German', 'Russian');
The begin
Result:=CountryNames [CountryCode];
end;

CodePudding user response:

To the upstairs:
Data is always will be, plus one minus one? Data size is too big to do,,

CodePudding user response:

This country code will change at any time??????? Data size can have how old? Hundreds of thousands of conspiracy,

CodePudding user response:

Var
LListName: TStringList;
The begin
LListName:=TStringList. Create;
LListName. Add (' EGY=Egypt);
LListName. Add (' CHN=China);
LListName. Add (' TWN=China Taiwan);
Self. Caption:=lListName. Values [' CHN '];
LListName. Free;

CodePudding user response:

The
refer to 12 floor response:
enumerated types, dear boss,

Type
TCountryCodes=(CHN, BRA, DEU, RUS);

The function GetCountryName (const CountryCode: TCountryCodes) : string;
Const
CountryNames: an array of string=[TCountryCodes] (' China ', 'Brazil',...

+ 1

CodePudding user response:


In case the xyz of
EGY: showmessage (' Egypt);
CHN: showmessage (' China ');
IRL: showmessage (' Ireland);
TWN: showmessage (' Taiwan ');
{here omit}

end;

CodePudding user response:

The
refer to 12 floor response:
enumerated types, dear boss,

Type
TCountryCodes=(CHN, BRA, DEU, RUS);

The function GetCountryName (const CountryCode: TCountryCodes) : string;
Const
CountryNames: an array of string=[TCountryCodes] (' China ', 'Brazil',...


The standard method

CodePudding user response:


In case the xyz of
EGY: showmessage (' Egypt);
CHN: showmessage (' China ');
IRL: showmessage (' Ireland);
TWN: showmessage (' Taiwan ');
{here omit}

end;

CodePudding user response:

The
refer to 12 floor response:
enumerated types, dear boss,

Type
TCountryCodes=(CHN, BRA, DEU, RUS);

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related