The string is used as a discriminant variable in the case of Delphi's case
Chen Jiaxin ╱jarsing@cina.chu.edu.tw
● Preface
When the casement is mentioned, the application case we will associate will be the case that is through one discriminant variable, and the process process will continue to perform in accordance with different conditional conditions. Alternatively, when we have a series of IFs in the group, we often think of simplifying program code and bonts its readability and execution efficiency.
However, in some cases, the CASE is not applicable to our program because the confirmed variables allowed to accept are limited to any form of an expression and ordinal type, this so-called "." The order of the order is integer, the character, the list, the cloth, the cloth and the collection, etc., and can be applied to such as ORD (), PRED (), SUCC (), Low () and high (), etc. The type of letter (see [1]).
Unfortunately, strings are obviously not the one of the order, and at some time (it will be exemplified below), when the condition variable is the string and the conditional branches are quite a lot, although helpless, In addition to using a lot of IF and else IF, it seems that there is no other way, hehe.
For example, the following program code is not allowed in Delphi:
# 001 VAR
# 002 str: String; // Declare the discrimination of String type
# 003 Begin
# 004 Case Str OF / / Error Message: Ordinal Type Required
# 005 // ...
# 006 End;
# 007 END;
This will not be compiled, so the conventional solution is usually converted to a large number of IF and ELSE IF a combination of sentences. At this time, I really hope that we use Visual Basic because the following program code is allowed by its compiler (see [5]):
# 001 DIM STR AS STRING 'Declare the discrimination of String
# 002 SELECT CASE STR 'is equivalent to the CASE of Delphi
# 003 '...
# 004 end select 'ok, compile
So, in this article, the author tries to find this problem as the starting point, and "In addition to converting the traditional solution of IF and else IF," finding other feasible responses, and sincerely hope this paper is for this issue. People who need to seek solutions (after reading [12] - [14], the author has discovered that it can help.
First, let go, the author intends to introduce seven solutions, where the top five methods are the contents of [9] - [13], while the sixth is the comprehensive multi-vector load of the author. (OVERLOADING) version. These programs are:
V Solution 1: Search String Array
V Sproducts: Using Real Search
V Solution 3: Using the mixed function
V Sprodule 4: Nest Casses CASE
V Solution 5: Use TStringList
V Solution 6: Practical multi-load letter
V Solution 7: Applying ready-made letters