Brian Dunning's FileMaker Custom Functions

TXT_to_UTF8 ( Text )

Converts text to UTF-8 encoding

  Average rating: 3.9 (49 votes) Log in to vote

Ibrahim Bittar Torres   Ibrahim Bittar Torres - Show more from this author
Eikonsys, S.A. de C.V.
http://www.eikonsys.com

Share on Facebook Share on Twitter

  Sample input:
TXT_to_UTF8 ( "México" )
  Sample output:
México

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Each Unicode character has an UTF-8 byte value, however, the representation of these values in a text field in FileMaker are different depending on the platform. This is because the Mac Roman and the Windows 1252 (wrongly known as Latin-1) character encoding tables are different.

For example, if you want to convert the â character to UTF-8 see what happens:

In UTF-8 the character â is represented by the bytes C3 A2. If you look into the Mac Roman table you'll find that C3 is √ and A2 is ¢ but in the Windows table C3 is à and A2 is ¢ so to represent a high ASCII character in UTF-8 you need to use both characters. √¢ for Mac and â for Windows.

This is exactly what this CF does. It substitutes every high ASCII character with its corresponding character pair on the Mac Roman or Windows 1252 encoding table.

This is very useful to encode an XML text calculation before converting to Base64 and sending it to a web service for example.

Enjoy.

 

Comments

Ibrahim Bittar   Ibrahim Bittar, León, México
Aug 11, 2014
This function has been updated so the platform is no longer needed as a parameter. I also fixed some bugs on Windows conversion.
 
Jody Barney   Jody Barney, Codence
Jun 28, 2022
Added this additional substitution to the existing custom function to assist with a specific issue that arose during an import/export scripting process. [ "�"; "'" ]
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: