| Components | All | New | MacOS | Windows | Linux | iOS | ||||
| Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old | |
Text.ReadTextFromContainer
Reads content of container value as text.
| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
| Text | 4.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
MBS( "Text.ReadTextFromContainer"; Container { ; Encoding } ) More
Parameters
| Parameter | Description | Example | Flags |
|---|---|---|---|
| Container | The container field or variable containing container value. | $myData | |
| Encoding | The text encoding for result. Default is native. This function can also handle UTF-16 as well as UTF-16LE and UTF-16BE for little/big endian byte order. Possible encoding names: ANSI, ISO-8859-1, Latin1, Mac, Native, UTF-8, DOS, Hex, Base64 or Windows. More listed in the FAQ. |
UTF8 | Optional |
Result
Returns text or error.
Description
Reads content of container value as text.You need to be sure it is text and the text encoding. Else you may get garbage.
Examples
Reads text from container:
MBS( "Text.ReadTextFromContainer"; test::test; "UTF8" )
Extract text from gzip compressed text with prefixed length:
# get some response string, gzip compressed with length before
// Set Variable [ $response ; Value: GzipDecompress::InputString ]
Set Variable [ $response ; Value: "RAAAAB+LCAAAAAAABACrZlBicGbIZ0hhSAWyrBhMGAwYDBl0gOwwhkSGHIZSqLgSEIJEg4BqSxlKkE RrGQAjtv6kRAAAAA==" ]
# convert base64 to Hex
Set Variable [ $hex ; Value: MBS( "Text.DecodeHexFromBase64"; $response ) ]
# now we can remove the first 4 bytes with length
Set Variable [ $hexNum ; Value: Left($hex; 8) ]
Set Variable [ $Rest ; Value: Middle ( $hex; 9; 100000000 ) ]
# we can decode the length value
Set Variable [ $len ; Value: MBS("Math.DecodeNumber"; "Integer"; 32; $hexNum) ]
# and read to container value from hex
Set Variable [ $Cont ; Value: MBS( "Container.DecodeFromHex"; "FILE"; $Rest; "test.gz" ) ]
# now decompress gzip
Set Variable [ $Decompressed ; Value: MBS( "Archive.GZipDecompress"; $cont; "test.txt") ]
# and read it as text. it is little endian UTF-16 here!
Set Variable [ $result ; Value: MBS( "Text.ReadTextFromContainer"; $Decompressed; "UTF-16LE") ]
# show in field
Set Field [ GzipDecompress::OutputString ; $result ]
Show Custom Dialog [ "Result" ; $result ]
Example result:
{"Code":401,"Value":"","Route":""}
// Set Variable [ $response ; Value: GzipDecompress::InputString ]
Set Variable [ $response ; Value: "RAAAAB+LCAAAAAAABACrZlBicGbIZ0hhSAWyrBhMGAwYDBl0gOwwhkSGHIZSqLgSEIJEg4BqSxlKkE RrGQAjtv6kRAAAAA==" ]
# convert base64 to Hex
Set Variable [ $hex ; Value: MBS( "Text.DecodeHexFromBase64"; $response ) ]
# now we can remove the first 4 bytes with length
Set Variable [ $hexNum ; Value: Left($hex; 8) ]
Set Variable [ $Rest ; Value: Middle ( $hex; 9; 100000000 ) ]
# we can decode the length value
Set Variable [ $len ; Value: MBS("Math.DecodeNumber"; "Integer"; 32; $hexNum) ]
# and read to container value from hex
Set Variable [ $Cont ; Value: MBS( "Container.DecodeFromHex"; "FILE"; $Rest; "test.gz" ) ]
# now decompress gzip
Set Variable [ $Decompressed ; Value: MBS( "Archive.GZipDecompress"; $cont; "test.txt") ]
# and read it as text. it is little endian UTF-16 here!
Set Variable [ $result ; Value: MBS( "Text.ReadTextFromContainer"; $Decompressed; "UTF-16LE") ]
# show in field
Set Field [ GzipDecompress::OutputString ; $result ]
Show Custom Dialog [ "Result" ; $result ]
Example result:
{"Code":401,"Value":"","Route":""}
Count pages in a PDF document:
Let( [
text = MBS("Text.ReadTextFromContainer"; Test::ContainerField);
Count = PatternCount ( text ; "/Page " )
// works only if page markers are not compressed or encrypted.
]; Count)
text = MBS("Text.ReadTextFromContainer"; Test::ContainerField);
Count = PatternCount ( text ; "/Page " )
// works only if page markers are not compressed or encrypted.
]; Count)
See also
- Archive.CompressText
- Archive.GZipDecompress
- BinaryFile.ReadText
- Container.DecodeFromHex
- Container.GetText
- FM.InsertRecordCSV
- Math.DecodeNumber
- Text.DecodeHexFromBase64
- Text.RTFToText
Blog Entries
FileMaker Magazin
This function is free to use.
Created 18th October 2014, last changed 25th February 2026