DEV Community

Peter + AI
Peter + AI

Posted on

๐Ÿงน Clean Your Strings: Understanding Uniface's $stripattributes Function

โš ๏ธ This blog post was created with AI assistance.

๐Ÿ“ What is $stripattributes?

In Uniface 10.4, the $stripattributes function is your go-to tool when you need to clean up formatted text. It removes character attributes like bold, italic, and underline, as well as frames and rulers from a string.

Think of it as a text cleaner that strips away all the visual formatting, leaving you with plain text. ๐Ÿงผ

๐Ÿ”ง How to Use It

The syntax is simple:

$stripattributes(String)
Enter fullscreen mode Exit fullscreen mode

Where String can be:

  • A string literal
  • A field name
  • A variable
  • A function that returns a string

๐Ÿ’ก Practical Example

Let's say you have a field called MYFIELD that contains formatted text. You want to copy this text to an edit box without any formatting:

MYFIELD = "aaabbb"
EDITBOX = $stripattributes(MYFIELD)
; EDITBOX now contains "aaabbb" without formatting
Enter fullscreen mode Exit fullscreen mode

๐ŸŽฏ When Should You Use It?

Here are some common scenarios where $stripattributes comes in handy:

1๏ธโƒฃ Data Export

When exporting data to CSV or text files, you don't want formatting attributes to mess up your output. Use $stripattributes to ensure clean, plain text.

2๏ธโƒฃ Database Storage

If you need to store text in a database field that doesn't support formatting, strip the attributes first to avoid character encoding issues.

3๏ธโƒฃ Text Processing

When comparing or searching through text, formatting can interfere with your logic. Clean the text first for accurate results.

4๏ธโƒฃ Copy Operations

Moving text between different UI components where one supports formatting and the other doesn't? Strip the attributes to prevent display issues.

โš ๏ธ Important Note

In Uniface 10.4, characters that aren't supported in the target character set are NOT stripped from the string. This is different from Uniface 8, where they were removed. Keep this in mind when working with special characters! ๐Ÿ”ค

๐Ÿš€ Where Can You Use It?

Good news! The $stripattributes function works in all Uniface component types, so you can use it anywhere in your application. โœจ

๐ŸŽ“ Quick Tips

  • Always test your output: Make sure the stripped text looks as expected, especially with international characters.
  • Combine with other functions: You can use $stripattributes together with functions like $trim or $uppercase for more complex text processing.
  • Performance: This function is lightweight and fast, so don't worry about using it frequently in your code.

๐Ÿ”— Related Functions

If you're working with text formatting, you might also want to check out:

  • $bold - Add bold formatting
  • $italic - Add italic formatting
  • $underline - Add underline formatting

๐Ÿ’ญ Final Thoughts

The $stripattributes function is a small but powerful tool in your Uniface toolkit. Whether you're cleaning up user input, preparing data for export, or ensuring consistent text display across different components, this function has you covered. ๐ŸŽ‰

Remember: clean data leads to fewer bugs and happier users! ๐Ÿ˜Š

Top comments (0)