Note: This blog post was created with the assistance of AI technology.
If you work with Uniface 10.4, you might have come across the $syntax function. This powerful tool helps you match text patterns in your applications. Let me show you how it works in simple terms! ๐ก
๐ What Does $syntax Do?
The $syntax function converts a regular string into a special pattern string. Think of it like creating a template that other strings can match against. This is super useful when you need to check if user input follows a specific format.
Basic Structure
$syntax(String, SyntaxMode)
- String: The text you want to convert
- SyntaxMode: How the matching should work (optional)
๐ฏ Syntax Modes Explained
Uniface offers four different modes to control how pattern matching works:
1. Classic Mode (Default) ๐ง
This mode treats special characters like #, *, &, @ as pattern codes.
$syntax("D&G")
This creates the pattern '%[X]D&G' which matches DOG, DIG, DUG, etc. The & acts as a wildcard for any single character!
2. CaseSensitive Mode ๐
Perfect when exact case matters! Special characters are treated as normal text.
$syntax("D&G", "CS")
This only matches the exact string "D&G" with the same uppercase letters.
3. CaseInsensitive Mode ๐ก
Ignores uppercase and lowercase differences. Great for user-friendly searches!
$syntax("D&G", "CI")
This matches D&G, d&g, D&g, or any combination of upper and lowercase.
4. NlsLocale Mode ๐
Handles special characters from different languages according to locale settings.
$syntax("i#B", "NlsLocale")
In Turkish locale, this correctly handles the dotted and dotless "i" characters!
๐ผ Real-World Example
Imagine you need to check if a customer name matches a pattern:
if (NAME1 = $syntax("D&G", "CaseInsensitive"))
; Name matches the pattern
message "Name matches!"
else
; Name doesn't match
message "Name doesn't match."
endif
This checks if the NAME1 field contains text matching the pattern, ignoring case differences.
โ ๏ธ Important Things to Remember
- The pattern must appear within the first 256 characters of the string you're checking
- If something goes wrong,
$syntaxreturns an empty string - Check
$procerrorfor error details (value -1013 means invalid syntax string) - You can use this function in all Uniface component types
๐ When Should You Use $syntax?
Here are some practical scenarios:
- Form Validation: Check if user input matches required formats
- Search Features: Create flexible search that ignores case
- Data Filtering: Find records matching specific patterns
- International Apps: Handle text with special characters correctly
๐ Pro Tips
- Start Simple: Use "Classic" mode first to understand pattern codes
- Test Thoroughly: Different modes behave very differently
- Handle Errors: Always check
$procerrorafter using$syntax - Choose the Right Mode: Match the mode to your business requirements
โจ Conclusion
The $syntax function is a powerful tool in your Uniface toolkit. Whether you need exact matching, case-insensitive searches, or international character support, there's a mode for your needs. Start experimenting with simple patterns and gradually work your way up to more complex scenarios! ๐
Happy coding! ๐จโ๐ป๐ฉโ๐ป
Top comments (0)