Character and string processing functions: Character and string processing functions are all character data, but their return value types are different.
1. Take the SUBSTRING function:
Format: substr (C,N1,N2)
Function: Take the string C N1 character character N2 characters. The return value type is a character type.
Example: Take a last name in a string of names.
Store "Wangxiaolin" to XM
? substr (xm,1,2)
The result is: Wang
2. Delete the space function: The following 3 functions can delete the extra spaces in the string, and the return values of the 3 functions are all character types.
Trim (string): Delete trailing spaces of a string
Alltrim (string): Delete the front and back spaces of a string
LTrim (string): Delete the preceding space of a string
Example: Removing the trailing space of the first string and connecting to the second string
Store "ABCD" to X
Store "EFG" to Y
? Trim (x) +y
Abcdefg
3. Space function:
Format: space (n)
Description: The function's function is to produce a specified number of space strings (n is used to specify the number of spaces).
Example: Define a variable DH with a initial value of 8 spaces
Store space (8) to DH
4. Take the left sub-string function:
Format: Left (c,n)
Function: Take the left n characters of the string C.
5. Take the right substring function:
Format: Right (C,n)
function: Take the n characters to the right of the string C
Example: a= "I am Chinese"
? Right (a,4)
People
? Left (a,2)
I
6.empty (c): Used to test whether string C is a space.
7. Find the substring position function:
Format: at (string 1, String 2)
Function: Returns the position of string 1 in string 2
Cases:? At ("Prof.", "Associate Professor")
2
8. Uppercase and lowercase conversion functions:
Format:
Lower (String)
Upper (String)
Function: Lower () The letters in the string are all lowercase; upper () capitalizes the letters in the string
Cases:
Bl= "FoxBASE"
? Lower (BL) +space (2) +upper (BL)
Foxbase Foxbase
9. Find the string length function:
Format: Len (String)
Function: The length of the specified string
Example: A= "Chinese"
? Len (a)
6
Two. Mathematical operation function:
1. Take the whole function:
Format: Int (numeric)
Function: Takes the integer portion of the specified value.
Example: rounding and displaying results
? int (25.69)
25
2. Rounding Function:
Format: round (numeric expression, number of decimal digits)
Function: Rounding the calculation results of the numeric expression according to the given rounding decimal digits
Example: Rounding out the number given below and displaying its result
? Round (3.14159,4), round (2048.9962,0), round (2048.9962,-3)
3.1416 2049 2000
3. Find the square root function:
Format: sqrt (numeric)
function: The arithmetic square root of the specified numeric value
Example: sqrt (100)
10
4. Maximum value, minimum function:
Format:
Max (numeric expression 1, numeric expression 2)
Min (numeric expression 1, numeric expression 2)
Function: Returns the maximum and minimum values in two numeric expressions
Cases:
x1=123.456
x2=234.567
? Max (X1,X2)
234.567
? min (x1,x2)
123.456
5. Find the remainder function:
Format: mod (expression 1, expression 2)
Function: Find the remainder of expression 1 for expression 2
Cases:
? mod (10,3)
1
6. Calculate the exponent, logarithmic function:
Format:
exp (Numeric expression)
Log (numeric expression)
Function:
(1). EXP () calculates the base of the natural number E, and the value of the expression is the power of the exponent
(2). log () evaluates the natural logarithm of the expression value, returning the value of LNX.
Cases:
X=1
Y=exp (x)
? exp (x), log (x)
2.72 1
Three. Conversion function:
1. Numeric to numeric string function:
Format: STR (N,N1,N2)
Function: Converts a value n to a string, N1 to a total length, and N2 to a decimal place
Example:? str (321.56)
322 Implicit rounding rounding conversion to character data
? STR (321.56,6,2)
321.56
2. Character to numeric function:
Format: Val (s)
Function: Converts a numeric string s to a numeric value
Example: x= "23"
Y= "76"
? val (x) +val (y)
100
3. Character Turn Date function:
Format: Ctod (c)
Function: Converts the date string C to a date
Example: set date ANSI format for American Standardization Association
? Ctod ("^2005.11.14")
2005.11.14
4. Date-to-character function:
Format: Dtoc (d)
Function: convert Date d to date string
Example: convert date data to character date data and display the kanji date.
Set century on to turn on the century prefix, that is, the year of the date is represented by 4 bits
Set Date ANSI
RQ={^2005.11.14}
Rq=dtoc (RQ)
SUBSTR (rq,1,4) + "year" +substr (rq,6,2) + "Month" +substr (rq,9,2) + "Day"
November 14, 2005
5. Time-to-character function:
Format: Ttoc (Time)
Function: Convert time to TIME string
6. Character Turn time function:
Format: Ctot (c)
Function: Convert time string to time
7. String substitution function:
Format: Stuff (character expression 1, starting position, number of characters, character expression 2)
Function: Starting at the specified position, use the value of expression 2 to replace the specified number in expression 1. If the number of characters is zero, insert directly; If Expression 2 is an empty string, delete the specified number of characters in Expression 1.
Example: x= "I wish you all a good New year!"
? Stuff (x,7,4, "Spring Festival")
I wish you a good spring festival
? Stuff (x,11,0, "Spring Festival")
I wish you all a good New year spring
? Stuff (x,7,4, "")
I wish you all the best
8. Character representable Ascⅱ code function:
Format: ASC (character expression)
Function: Turn the first character in the left character expression to the corresponding Ascⅱ code value
Example: x= "Foxpro"
? ASC (x), ASC (lower (x))
70 102
9.ascⅱ code value to character function:
Format: Chr (numeric expression)
Function: Converts the value to the corresponding Ascⅱ code character, the return value is the character type
Example: Chr (+CHR) (111) +CHR (111+9)
Fox
Four. Date function:
1. System Date Function:
Format: Date ()
Function: gives the current date of the system, and the return value is the date type data.
Example: Displaying the system date
? Date ()
11/14/05
Set Date ANSI
Set century on
? Date ()
2005.11.14
2. Annual, monthly, and daily functions:
Format: (1). Year (date expression): Returns a four-bit number of years from a date expression.
(2). month (date expression): Returns a number-represented month in a date expression.
(3). Day (date expression): Returns a number of days in a date expression.
Example: Test system date
Rq=date ()
? Year (RQ), Month (RQ), Day (RQ)
2005 11 14
3. System Time Function:
Format: Time ()
Function: Get the current time string
Example:? Time ()
20:32:26
4. System date-time function:
Format: DateTime ()
Function: Get Current date Time
Example:? DateTime ()
2005.11.14 08:35:12 PM
5. Week function:
Format: Dow (date expression)
Cdow (date expression)
Function: Dow uses numbers for the week, 1 for Sunday, 7 for Saturday; Cdow in English for the week
Example:? date ()
2005.11.15
? Dow (Date ()), Cdow (date ())
3 Tuesday
Five. Test function:
1. Test the file tail function:
Format: EOF ([n])
Description
(1). n Specifies the work area code to be measured, the range is 1~32767
(2). This function is used to test whether the record pointer of a table in the specified workspace points to the end of the file, returns the True value, otherwise returns false values, or omit the option to refer to the current workspace.
Example: Test file record pointer pointing to end of file
Use staff file
Go Bottom
? EOF ()
. F.
Skip
? EOF ()
. T.
2. Test the file header function:
Format: BOF ([n])
Description
(1). n Specifies the work area code to be measured, the range is 1~32767
(2). Used to test whether a record pointer to a table in the specified workspace points to a file header, true if it is true, otherwise false values are omitted;
Example: Test record pointer to file header
Use staff file
Go top
? BOF ()
. F.
Skip-1
? BOF ()
. T.
3. Test the current record number function:
Format: Recno ()
Function: Get the current record number
Cases:
Use staff file
? Recno ()
1
Skip
? Recno ()
2
4. Test table file record number function:
Format: RecCount ()
Function: Gets the number of records in the table
Example: Testing the number of records in the "Staff records" table
Use staff file
? RecCount ()
5
5. Test table field number function:
Format: Fcount ()
Function: Gets the current number of fields
Example: How many fields are there in the Staff records table?
Use staff file
? Fcount ()
9
6. Test whether the lookup record is a success function:
Format: Found ()
Function: Test the Find, seek, and locate commands for success. Returns true if successful, otherwise a false value.
Example: Finding the education level of "Xiao Gang" in the "Staff files" table
Use staff file
Locate for name = "Xiao Gang"
? found ()
. T.
Display
7. File Test function:
Format: file (character expression)
Function: Test character expression Specifies whether the file exists
Example: File ("E:\myvfp\ staff file. dbf")
. T.
8. Data type test function:
Format: type (character expression)
Function: Test the data type of an expression, return uppercase letters: N (numeric), C (character), L (logical), D (date), M (remarks)
Cases:
x=1236
y= "Hello"
? type ("X")
N
? type ("Y")
C
9. Test the workspace function:
Format: Select ()
Function: Returns the area code of the current workspace
10. Test the alias function:
Format: Alias ()
Function: Test the alias of the current workspace
Cases:
Select 1
Use employee file alias Zgda
Select 2
Use wage situation
? Alias ()
Wage situation when you open a table, you do not specify an alias, and the table name is an alias
Select Zgda Choose a workspace by alias
? Select ()
1
11. Table File name function:
Format: DBF ()
Function: Returns the name of the table opened in the current workspace
Cases:
Use wage situation
? DBF ()
E:\myvfp\ Wage situation
Six. Other functions:
1. Macro substitution function:
Format: variable name
Description: Only the macro substitution function in VFP has no parentheses. The function is to return the string that is stored in the specified character type variable.
Example: Pay 100 yuan for each person in the "salary situation" table
gz= "Wages"
Use wage situation
Replace all GZ with gz+100
2. Conditional function:
Format: IIF (expression, expression 1, expression 2)
Function: Returns the value of expression 1 if the expression value is true, otherwise returns the value of expression 2; The function return value type is the same as expression 1 or expression 2 type
A=3
B=5
? IIF (AB, "Happy", "Happy")
Happy
3. Message box functions:
Format: MessageBox (hint Text [, dialog box type [, dialog title text]])
Features: Display prompt dialog box
Description
(1) dialog box type:
dialog box type features
0 "OK" button only
1 "OK" and "Cancel" buttons
2 "Terminate", "Retry" and "Ignore" buttons
3 "yes", "No" and "Cancel" button
4 "Yes" and "no" buttons
5 "Retry" and "Cancel" buttons
The Stop icon
32. Icons
48! icons
I icon
0 Default 1th button
256 Default 2nd button
512 Default 3rd button
(2). return value:
return value button
1 OK
2 Cancel
3 termination
4 retry
5 Ignore
6 is
7 No
Example: Parsing the MessageBox ("Are you sure you want to exit the system?", 4+64, "hint message") What kind of window pops up.
Analysis: Looking back at the format of this function, the prompt text in the popup dialog is "Are you sure you want to exit the system" and the dialog box title is "Prompt Message",
There is "4+64" in the middle of the function, where the "yes" and "No" two buttons appear in the 4 specified dialog box (see table 1) and the I icon appears in the 64 specified dialog box (see table 2)
OK, we execute the following commands in the command window in turn:
Tui=messagebox ("Are you sure you want to exit the system?", 4+64, "hint message")
The variable TUI is used to receive the return value of the MessageBox function, which pops up the window 1
? tui
The variable TUI value depends on which button the user points at runtime, if "Yes" is clicked, returns 6, if "No" is clicked, returns 7, see table 2
Description: In practice, we often add the following code to the System menu or to the form's exit button:
Tui=messagebox ("Are you sure you want to exit the system?", 4+64, "hint message")
If tui=6 if this condition is true, the user points the "Yes" button, executes the QUIT command, exits safely
Quit
endif
Linux converts time-type values to numeric