β οΈ Note: This blog post was created with the help of AI to make Uniface documentation more accessible to developers.
π What is $string?
The $string function in Uniface 10.4 is a powerful tool that converts XML entities into their actual character representations. Think of it as a translator that takes encoded text and turns it back into readable characters. π
An XML entity is basically a special code that represents a character. For example, < represents the less-than symbol (<).
β¨ Why Should You Care?
When working with web applications or data exchange, you often encounter XML entities. The $string function helps you:
- β Convert encoded XML data back to readable text
- β Generate any Unicode character programmatically
- β Handle special characters safely in your Uniface applications
- β Work with international characters and symbols
π§ Basic Syntax
The syntax is straightforward:
$string("Your text with XML entities here")
π What XML Entities Can You Use?
Standard XML Entities π
These are the five predeclared XML entities that work everywhere:
-
<β Less than sign (<) -
>β Greater than sign (>) -
&β Ampersand (&) -
'β Apostrophe (') -
"β Quotation mark (")
Unicode Characters π’
You can use decimal or hexadecimal format:
- Decimal:
Agives you "A" - Hexadecimal:
Aalso gives you "A"
Uniface Special Entities π¨
Uniface provides custom entities for special characters:
-
&uNL;β New line (carriage return) -
&uTAB;β Tab character -
&uPG;β Page break -
&uSEP;β Subfield separator
π‘ Practical Examples
Example 1: Converting Basic XML Entities π―
vString1 = $string("XML has five predeclared entities.")
vString2 = $string("They are: <, >, &, ', and ".")
FLD = "%%vString1%%^%%vString2"
Result:
XML has five predeclared entities.
They are: <, >, &, ', and ".
Example 2: Generating the Alphabet with Unicode π€
This clever example shows how to generate all 26 uppercase letters programmatically:
$1 = 65
vString = ""
while($1 < 91)
vString = "%%vString%%%&#%%$1;"
$1 = $1 + 1
endwhile
FLD = $string(vString)
Result:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
π§ How it works: The code loops through ASCII values 65-90 (A-Z), builds a string of Unicode entities, then converts them all at once with $string.
β οΈ Important Things to Remember
- βοΈ
$stringworks in all Uniface component types - βοΈ Don't confuse this with the
$stringconverter used in$typed- they're different! - βοΈ You can combine multiple entity types in one call
- βοΈ Unicode gives you access to thousands of international characters
π Real-World Use Cases
1. Processing Web Form Data: When users submit forms with special characters, XML entities ensure safe transmission. Use $string to convert them back.
2. Internationalization: Generate characters from any language using Unicode values.
3. Data Integration: When receiving XML data from external systems, decode it properly for display or processing.
4. Dynamic Text Generation: Build formatted text with special characters programmatically.
π Quick Tips for Beginners
- πΈ Start with simple examples using standard XML entities
- πΈ Test your entity codes before using them in production
- πΈ Use hexadecimal Unicode (
&#x) when working with Unicode tables - it's easier to read - πΈ Remember that semicolons are required at the end of each entity
π¬ Conclusion
The $string function is a simple yet powerful tool in your Uniface toolkit. Whether you're processing XML data, working with international characters, or building dynamic content, understanding how to use XML entities will make your life easier. π
Start experimenting with the examples above, and you'll quickly master this useful function!
Happy coding! π¨βπ»π©βπ»
Top comments (0)