borland Packages Class Hierarchy dx.text Package
java.lang.Object +----java.text.Format +----com.borland.dx.text.TextFormat
Variables Constructors Properties Methods
Implements Serializable, Cloneable
This component extends the basic Format
class but allows for special formatting of text. Similar to other Format
derivatives, it is based on a control pattern. The format of the control pattern is as follows:
<pattern>; <keepLiterals>; <fillCharacter>; <replaceCharacter>
pattern
0 Digit 0:9, entry required, '+' and '-' not allowed 9 Digit 0:9, entry optional, '+' and '-' not allowed # Digit or space, entry optional, plus and minus signs allowed L Letter A:Z, entry required l Letter A:Z, entry optional ? Letter A:Z, entry optional A Letter A:Z or digit 0:9, entry required a letter A:Z or digit 0:9, entry optional C any character or space, entry required c Any character or space, entry optional & Any character or space, entry required < Causes all characters following to be converted to lowercase > Causes all characters following to be converted to uppercase ! Causes strings too short to fill from right to left \ Backslash escape -- allows any Unicode value to follow (e.g. "\u2003") ^ Initial place for cursor when editing begins ' Encloses a literal expression (for example, the pattern "990' units sold'" would display as "27 units sold") * Encloses a password encrypted string (for example the pattern "*AAAAaaaa*" would accept a password at least 4, and at most 8 alphanumeric characters). Characters typed or displayed appear as the '*' character
An example of a US phone number might be "!(999)000-0000"
keepLiterals
fillCharacter
replaceCharacter
fillCharacter
are replaced with replaceCharacter
. Using the example above, parsing "(***)555-5330" with the pattern "!(999)000-0000;1;*;_" produces "(___)555-5330". Again, a zero value is allowed in this field (using "\0") and has the effect of removing the fillCharacter
s.
keepLiterals
, fillCharacter
, replaceCharacter
) have their own setter and getter methods.
public static char NOT_A_CHAR = 0xffffNot a valid character.
public TextFormat()Constructs a
TextFormat
object with no specified string pattern.
public TextFormat(String pattern)Constructs a
TextFormat
object with the specified string pattern.
pattern
TextFormat
object with.
public char getFillCharacter() public void setFillCharacter(char c)Retrieves and sets the fill character used in the string.
c
public boolean getKeepLiterals() public void setKeepLiterals(boolean tf)Determines whether literals remain in the string when it is stored.
keepLiterals
is true when literals are stored; otherwise, it is false.
tf
tf
to true to store literals; set tf
to false remove literals when the string is stored.
public char getReplaceCharacter() public void setReplaceCharacter(char c)Retrieves and sets the character that replaces the fill character when the string is parsed.
c
public void applyPattern(String pattern)Sets the pattern to the specified value.
pattern
public final StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)Formats the given
Object
using the pattern associated with this object.
obj
Object
to be formatted.
toAppendTo
StringBuffer
to append the newly formatted String
to.
pos
StringBuffer
of the formatted String
.
public StringBuffer format(String toBeFormatted, StringBuffer result, FieldPosition pos)Formats the given
String
using the pattern associated with this object. If the input string has insufficient characters to fill the pattern, it is filled with the character indicated by setFillChar()
. The result
parameter is assigned the return value of this method.
toBeFormatted
String
to be formatted.
result
pos
StringBuffer
of the formatted String
.
public StringBuffer parse(String text, ParsePosition pos)This method parses (or decomposes) a
String
using the existing pattern. It allocates a new StringBuffer
and fills it with the parsed version of the text
parameter.
text
String
to parse.
pos
StringBuffer
of the parsed text.
public final Object parseObject(String source, ParsePosition pos)Parses (or decomposes) a
String
into an Object
.
source
String
to parse.
pos
StringBuffer
of the formatted String
.
public String toPattern()Returns the pattern used for formatting.