Complex interpretation of a simple function (String function)

Source: Internet
Author: User

Function function: this function can be used in two ways: type conversion, see syntax Format 2; type conversion and data format conversion, see Syntax 1. The focus is on format 1 learning and understanding.
Function Syntax: format 1: String (data, {format })
Format 2: String (Blob)
Data: The data to be converted to the type and format. It can be date, DateTime, numeric, time, or string type.
Format: format String, used to specify the display format of the parameter data. The data type varies depending on the parameter data. This parameter is required when the data type is String. Otherwise, this function is unnecessary.
Return Value: String. When the function is successfully executed, the specified data in string format is returned, if the data type of the data parameter does not match the format specified by the format parameter, the format specified by the format parameter is invalid, or the data parameter is not the appropriate data type mentioned above, String () the function returns an empty string ("").
Description: format is a string represented by a mask. The data type of the parameter has different usage:
The format of the data parameter is:
Positive number format; negative number format; zero display format;
The empty display format must be provided in the first part, and other parts can be omitted. The numeric display format uses two masked characters: # and 0, where # represents 0 ~ Any number between 9. 0 indicates that each zero is displayed. In addition, currency signs ($ or ¥), percent signs (%), decimal points (.), comma (,) and other characters can also appear in the format string, but, except the decimal point (.), comma (,) can appear between the format character # and 0, other characters can only be placed before or after the format string, for example ,###, ####### it is an incorrect Format String. It is a correct format string. If the format parameter is omitted, the String () function uses the default PowerBuilder format. Note: If the display format contains multiple parts, the semicolon (;) between each part cannot be omitted. Other characters can also appear in the display Format String (only at the beginning and end of the format string), but they have no special meaning and the system only displays them as they are. For example, when the value 12 is formatted using the display Format String "revenue #", the result is "revenue 12 ".
When the data parameter is of the String type, the syntax format of the format parameter is:
Normal string format; null format
In "normal string format", @ represents any character in the string, and any other character is displayed as is. For example, if the following format is defined:
(@@)@@@@-@@@@
The string 0166767593 is displayed as follows:
(01) 6676-7593
When the data parameter is of the Date type, the syntax format of the format parameter is:
Normal Date Format; format when date is null
The characters in the date format have the following meanings:
D -- number of days (such as 8) Starting with no 0)
Dd -- number of days with 0 on the START (for example, 08)
Ddd-abbreviation of the Week (such as Mon and Tue)
Dddd-Full name of a week (such as Monday and Tuesday)
M -- start with a month without 0 (for example, 8)
Mm -- month with 0 on the START (for example, 08)
Mmm-abbreviated month (for example, Jan or Feb)
Mmmm-Full name of a month (such as January and February)
Yy -- the year in double digits (for example, 97)
Yyyy -- the year represented by four digits (such as 1997)
In addition, you can use the following keywords as the date display format:
[General] short date format defined in Windows
[LongDate] long date format defined in Windows
[Expiry date] short date format defined in Windows
When the data parameter is of the Time type, the syntax format is:
Normal time format; format when time is null
The characters in the time format are as follows:
H -- start with an hour without 0 (for example, 6)
Hh -- hours with 0 on the START (for example, 06)
M -- starts with a minute without 0 (for example, 6)
Mm -- start with 0 minutes (for example, 06)
S -- starts with a second without 0 (for example, 6)
Ss -- starts with 0 seconds (for example, 06)
F -- starts with a microsecond without 0. You can specify 1 ~ 6 f, each representing a part of microseconds
AM/PM-use AM/PM to display the last and afternoon time in 12-hour format
Am/pm-use am/pm to display the last and afternoon time in 12-hour format
A/P -- display the upper and afternoon time with A/P, in 12-hour format
A/p -- display the upper and afternoon time with a/p, in 12-hour format
In addition, you can use the keyword [Time] in the display format to display the Time according to the format defined by the current Windows system.
When the data parameter is of the DateTime type, the syntax format is:
Normal Date and time format; format when date and time are null
The mask used by the date and time type is to combine the date mask and time mask.
Code example:
Example 1: The following statement converts a specified date to the format of Jan 1 and 1998:
String (, "mmmm dd, yyyy ")
Example 2: The following statement converts a DateTime-type value to a string of Jan 1, 1998 6 hrs and 8 min:
String (DateTime (1998-01-31,06: 08: 00), 'mmmm dd, yyyy h "hrs and" m "min "')
Example 3: The following statement sets string1 to 0123:
Integer li_num= 123
String ls_temp

Ls_temp = string (li_num, "0000; (000); *****; null ")
Example 4: The following statement sets string1 to 123:
Integer li_num =-123
String ls_temp

Ls_temp = string (li_num, "000; (000); *****; null ")
Example 5: Set string1 to *** in the following statement ****:
Integer li_num = 0
String ls_temp

Ls_temp = string (li_num, "0000; (000); *****; null ")
Example 6: The following statement sets string1 to NULL:
Integer li_num
String ls_temp

Setnull (li_num)
Ls_temp = string (li_num, "0000; (000); *****; null ")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.