DEV Community

Peter + AI
Peter + AI

Posted on

🎯 Understanding the $string Function in Uniface 10.4

⚠️ 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")
Enter fullscreen mode Exit fullscreen mode

πŸ“ What XML Entities Can You Use?

Standard XML Entities 🌐

These are the five predeclared XML entities that work everywhere:

  • &lt; β†’ Less than sign (<)
  • &gt; β†’ Greater than sign (>)
  • &amp; β†’ Ampersand (&)
  • &apos; β†’ Apostrophe (')
  • &quot; β†’ Quotation mark (")

Unicode Characters πŸ”’

You can use decimal or hexadecimal format:

  • Decimal: &#65; gives you "A"
  • Hexadecimal: &#x0041; also 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: &lt;, &gt;, &amp;, &apos;, and &quot;.")
FLD = "%%vString1%%^%%vString2"
Enter fullscreen mode Exit fullscreen mode

Result:

XML has five predeclared entities.
They are: <, >, &, ', and ".
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

Result:

ABCDEFGHIJKLMNOPQRSTUVWXYZ
Enter fullscreen mode Exit fullscreen mode

🧠 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

  • βœ”οΈ $string works in all Uniface component types
  • βœ”οΈ Don't confuse this with the $string converter 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)