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)