Fórum Máscaras #268179
11/02/2005
0
Fsflorencio
Curtir tópico
+ 0Posts
11/02/2005
Dbergkamps
Gostei + 0
12/02/2005
Vinicius2k
Posso estar enganado, mas acho q o melhor tutorial (ao menos para este caso) é o Help do Delphi, pois nunca vi nenhum material específico:
[b:bf983372c3]Máscaras :[/b:bf983372c3]
These are the special characters used in the first field of the mask: CharacterMeaning in mask !If a ! character appears in the mask, optional characters are represented in the returned string as leading blanks. If a ! character is not present, optional characters are represented in the returned string as trailing blanks. >If a > character appears in the mask, all characters that follow are in uppercase until the end of the mask or until a < character is encountered. <If a < character appears in the mask, all characters that follow are in lowercase until the end of the mask or until a > character is encountered. <>If these two characters appear together in a mask, no case checking is done and the data is formatted with the case present in the Value parameter. \The character that follows a \ character is a literal character. Use this character to use any of the mask special characters as a literal. LThe L character requires an alphabetic character only in this position. For the US, this is A-Z, a-z. lThe l character permits only an alphabetic character in this position, but doesn´t require it. AThe A character requires an alphanumeric character only in this position. For the US, this is A-Z, a-z, 0-9. aThe a character permits an alphanumeric character in this position, but doesn´t require it. CThe C character requires an arbitrary character in this position. cThe c character permits an arbitrary character in this position, but doesn´t require it. 0The 0 character requires a numeric character only in this position. 9The 9 character permits a numeric character in this position, but doesn´t require it. #The character permits a numeric character or a plus or minus sign in this position, but doesn´t require it. :The : character is used to separate hours, minutes, and seconds in times. If the character that separates hours, minutes, and seconds is different in the regional settings of the Control Panel, that character is substituted in the returned string. /The / character is used to separate months, days, and years in dates. If the character that separates months, days, and years is different in the regional settings of the Control Panel, that character is substituted in the returned string. ;The ; character is used to separate the three fields of the mask. _The _ character automatically inserts spaces into the returned string. Any character that does not appear in the preceding table can appear in the first part of the mask as a literal character. Literal characters are inserted automatically if the second field of the mask is 0, or matched to characters in the Value parameter if the second field is any other value. The special mask characters can also appear as literal characters if preceded by a backslash character (\). The second field of the mask is a single character that indicates whether literal characters from the mask are included in the Value parameter. For example, the mask for a telephone number with area code could be the following string: (000)_000-0000;0;* The 0 in the second field indicates that the Value parameter should consist of the 10 digits of the phone number, rather than the 14 characters that make up the final formatted string. A 0 in the second field indicates that literals are inserted into the Value string, any other character indicates that they should be included. The character to indicate whether literals should be included can be changed by changing the MaskNoSave constant that is declared in the MaskUtils unit. The third field of the mask is the character that appears in the returned string for blanks (characters that do not appear in Value). By default, this is the same as the character that stands for literal spaces. The two characters appear the same in the returned string. Note:When working with multibyte character sets, each special mask character represents a single byte. To specify double-byte characters using the L, l, A, a, C, or c specifiers, the mask characters must be doubled as well. For example, LL would represent two single-byte alphabetic characters or a one double-byte character. Only single-byte literal characters are supported.
[b:bf983372c3]Strings de formatação :[/b:bf983372c3]
Format strings passed to the string formatting routines contain two types of objects -- literal characters and format specifiers. Literal characters are copied verbatim to the resulting string. Format specifiers fetch arguments from the argument list and apply formatting to them.
Format specifiers have the following form:
"¬" [index ":"] ["-"] [width] ["." prec] type
A format specifier begins with a ¬ character. After the ¬ come the following, in this order:
An optional argument zero-offset index specifier (that is, the first item has index 0), [index ":"]
An optional left justification indicator, ["-"]
An optional width specifier, [width]
An optional precision specifier, ["." prec]
The conversion type character, type
The following table summarizes the possible values for type:
dDecimal. The argument must be an integer value. The value is converted to a string of decimal digits. If the format string contains a precision specifier, it indicates that the resulting string must contain at least the specified number of digits; if the value has less digits, the resulting string is left-padded with zeros.
uUnsigned decimal. Similar to ´d´ but no sign is output.
eScientific. The argument must be a floating-point value. The value is converted to a string of the form "-d.ddd...E+ddd". The resulting string starts with a minus sign if the number is negative. One digit always precedes the decimal point.The total number of digits in the resulting string (including the one before the decimal point) is given by the precision specifier in the format string—a default precision of 15 is assumed if no precision specifier is present. The "E" exponent character in the resulting string is always followed by a plus or minus sign and at least three digits.
fFixed. The argument must be a floating-point value. The value is converted to a string of the form "-ddd.ddd...". The resulting string starts with a minus sign if the number is negative.The number of digits after the decimal point is given by the precision specifier in the format string—a default of 2 decimal digits is assumed if no precision specifier is present.
gGeneral. The argument must be a floating-point value. The value is converted to the shortest possible decimal string using fixed or scientific format. The number of significant digits in the resulting string is given by the precision specifier in the format string—a default precision of 15 is assumed if no precision specifier is present.Trailing zeros are removed from the resulting string, and a decimal point appears only if necessary. The resulting string uses fixed point format if the number of digits to the left of the decimal point in the value is less than or equal to the specified precision, and if the value is greater than or equal to 0.00001. Otherwise the resulting string uses scientific format.
nNumber. The argument must be a floating-point value. The value is converted to a string of the form "-d,ddd,ddd.ddd...". The "n" format corresponds to the "f" format, except that the resulting string contains thousand separators.
mMoney. The argument must be a floating-point value. The value is converted to a string that represents a currency amount. The conversion is controlled by the CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, DecimalSeparator, and CurrencyDecimals global variables or their equivalent in a TFormatSettings data structure. If the format string contains a precision specifier, it overrides the value given by the CurrencyDecimals global variable or its TFormatSettings equivalent.
pPointer. The argument must be a pointer value. The value is converted to an 8 character string that represents the pointers value in hexadecimal.
sString. The argument must be a character, a string, or a PChar value. The string or character is inserted in place of the format specifier. The precision specifier, if present in the format string, specifies the maximum length of the resulting string. If the argument is a string that is longer than this maximum, the string is truncated.
xHexadecimal. The argument must be an integer value. The value is converted to a string of hexadecimal digits. If the format string contains a precision specifier, it indicates that the resulting string must contain at least the specified number of digits; if the value has fewer digits, the resulting string is left-padded with zeros.
Conversion characters may be specified in uppercase as well as in lowercase—both produce the same results.
For all floating-point formats, the actual characters used as decimal and thousand separators are obtained from the DecimalSeparator and ThousandSeparator global variables or their TFormatSettings equivalent.
Index, width, and precision specifiers can be specified directly using decimal digit string (for example "¬10d"), or indirectly using an asterisk character (for example "¬*.*f"). When using an asterisk, the next argument in the argument list (which must be an integer value) becomes the value that is actually used. For example,
Delphi example:
Format(´¬*.*f´, [8, 2, 123.456]);
is equivalent to
Format(´¬8.2f´, [123.456]);
C++ example:
TVarRec args[3] = {8,2,123.456};
Format("¬*.*f", args, 2);
is equivalent to
TVarRec args[1] = {123.456};
Format("¬8.2f", args, 0);
A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (a "-" character preceding the width specifier), the result is left-justified by adding blanks after the value.
An index specifier sets the current argument list index to the specified value. The index of the first argument in the argument list is 0. Using index specifiers, it is possible to format the same argument multiple times. For example "Format(´¬d ¬d ¬0:d ¬1:d´, [10, 20])" produces the string ´10 20 10 20´.
Note:Setting the index specifier affects all subsequent formatting. That is, Format(´¬d ¬d ¬d ¬0:d ¬d´, [1, 2, 3, 4]) returns ´1 2 3 1 2´, not ´1 2 3 1 4´. To get the latter result, you have must use Format(´¬d ¬d ¬d ¬0:d ¬3:d´, [1, 2, 3, 4])T+
Gostei + 0
12/02/2005
Fsflorencio
Isto já serve.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)