Vincent_L

UnQuote (string) Function published

Discussion created by Vincent_L on Apr 10, 2018
Latest reply on Apr 11, 2018 by Vincent_L

Hi,

 

I just published my very first Custom Function, UnQuote

FileMaker Custom Function:UnQuote ( string )

 

This does what it says, it reverse Filemaker's Quote ( string) function.

 

// v.1.02

// This function aims to replace the Evaluate functions, to "UnQuote" Text returned by the quote function.

// IT ONLY WORKS ON TEXT THAT HAVE BEEN QUOTED BY THE FILEMAKER QUOTE FUNCTION,

// there's no point to UnQuote non Quoted text, we can't undo what's not done

// It's much much much faster than Evaluate (which can be ultra slow : 2h16, for 17,8 MB of Text)

// So Evaluate(Quote(string))=UnQuote(Quote(string)), so we're back to the original contents of the string

// It has been made by comparing the real output of Quote() on the first 65 536 unicode chars . Which determined that Quote does :

// Replaces " by \", and their smartquote versions

// Replaces ¶ by \¶

// Replaces char(13), ie carriage returns, by char(182) pilcrow, wich is like ¶,

// but not exactly -> so we need to protect real pilcrows that are converted to \¶ before re-replacing ¶ to char(13)

// © VincentL 2018/04/10 completly free to use, modifiy etc…

 

If(not IsEmpty(string);

Let(

[

string=If(Left(string;1)="\"";Right(string;Length(string)-1);string);

string=If(Right(string;1)="\"";Left(string;Length(string)-1);string);

string=Substitute(string;

 

[Char(92)&Char(92);"{ThisIsARealBackslash}"]; // we need to account for escaped \ by \\

[Char(92)&Char(34);Char(34)]; // we subsititue back \" to "

[Char(92)&Char(8220);Char(8220)]; // we subsititue back \“ to “ smartquote

[Char(92)&Char(8221);Char(8221)]; // we subsititue back \” to ” smartquote

[Char(92)&Char(8222);Char(8222)]; // we subsititue back \” to ” smartquote

[Char(92)&Char(8223);Char(8223)]; // we subsititue back \‟ to ‟ smartquote

[Char(92)&Char(182);"{ThisIsARealPilcrow}"]; // we protect real pilcrows

[Char(182);Char(13)]; // once the real pilcrows protected, the remaining pilcrows are the ones that Quote inserted in place of char(13), so we change them back to char(13). N.B we use char(182) instead of ¶ because otherwise, the ¶ remains

["{ThisIsARealPilcrow}";Char(182)];

["{ThisIsARealBackslash}"; Char(92)]

)];

string

))

 

Capture d’écran 2018-04-11 à 12.22.05.png

 

 

You can find a file including a Testbed to test it against any text you want below.

Attachments

Outcomes