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