In the student information system, we need to add the birth date and admission date when adding students to the student status. when the average person does not know the Add format, they will be written as 2013.8.7 or 2013/8/7, few people write the date format as 2013-8-7, and our database receives the date format 2013-8-7. So how can we make it easier for users to receive data! Next I will introduce a function.
The Replace () function, which means "substitution", can solve the problem encountered above.
Returns a string in which the specified substring has been replaced with another substring and the number of times it has been replaced is also specified.
Syntax
Replace (Expression,Find,Replacewith[,Start[,Count[,Compare])
ReplaceFunction syntax includes the following parts:
Part |
Description |
Expression |
Required. String expression that contains the substring to be replaced. |
Find |
Required. The substring to be searched. |
Replacewith |
Required. The substring to replace. |
Start |
Optional. Start position of the substring search in the expression. If this parameter is ignored, start from 1. |
Count |
Optional. The number of times the substring is replaced. If ignored, the default value is-1, which indicates all possible replacements. |
Compare |
Optional. Numeric value, indicating the comparison method used to determine the substring. For more information about the value, see "set value. |
Suppose we write in the code to confirm to add information to write
Text1.text = Replace (text1, ".", "-") 'in the text box 1, it is a searched character.-It is a replacement character.
Enter 2013.8.7 in the text1 text box and click OK.
The character received by the database is 2013-08-07. The slash/is also replaced.