文字コードを指定してBase64Encode

FileMaker 18以降

使用できる文字コードは、FileMakerの「関数:TextEncode」で使用されるテキストエンコードになります。

「関数:TextEncode」

 

SHIFT-JIS, SHIFT_JIS, base64エンコード, Base64Encode

function(関数):
Sample input(入力例):
Sample output(出力例):
formula(式):

Let([
¢Hex=HexEncode ( TextEncode ( Text ; Enc ; 1 ) )
;$Binary=
While ( 
	[ 
		$LIST=""
		;¢MAX = Length ( ¢Hex ) 
		;¢n = 1 
	] ; 
	¢n  ≤  ¢MAX; 
	[
		¢STR=Middle (¢Hex ; ¢n ; 1 )
		;$LIST=List($LIST;
			Substitute ( ¢STR ;["0";"0000"] ;["1";"0001"] ;["2";"0010"] ;["3";"0011"] ;["4";"0100"] ;["5";"0101"] ;["6";"0110"] ;["7";"0111"] ;["8";"1000"] ;["9";"1001"] ;["A";"1010"] ;["B";"1011"] ;["C";"1100"] ;["D";"1101"] ;["E";"1110"] ;["F";"1111"] )
			)//List
		;¢n = ¢n+ 1 

	] ;
Substitute ( $LIST ; [Char(10) ; ""] ; [Char(13)  ; ""])
 )


;$Base64=
While ( 
	[ 
		$LIST =""
		;$Base64=""
		;¢Length = Length ( $Binary ) 
		;¢Surplus =Mod ( ¢Length ; 6 )
		;$Binary = $Binary & If ( ¢Surplus    >   0 ; Left ( "000000" ; 6 - ¢Surplus  ))
		;¢MAX = Length ( $Binary ) 
		;¢n = 1 
	] ; 
	¢n  ≤  ¢MAX; 
	[
		¢STR6=Middle ($Binary ; ¢n ; 6 )
		;$LIST=List($LIST;Substitute ( ¢STR6
; ["000000" ; "A"]
; ["000001" ; "B"]
; ["000010" ; "C"]
; ["000011" ; "D"]
; ["000100" ; "E"]
; ["000101" ; "F"]
; ["000110" ; "G"]
; ["000111" ; "H"]
; ["001000" ; "I"]
; ["001001" ; "J"]
; ["001010" ; "K"]
; ["001011" ; "L"]
; ["001100" ; "M"]
; ["001101" ; "N"]
; ["001110" ; "O"]
; ["001111" ; "P"]
; ["010000" ; "Q"]
; ["010001" ; "R"]
; ["010010" ; "S"]
; ["010011" ; "T"]
; ["010100" ; "U"]
; ["010101" ; "V"]
; ["010110" ; "W"]
; ["010111" ; "X"]
; ["011000" ; "Y"]
; ["011001" ; "Z"]
; ["011010" ; "a"]
; ["011011" ; "b"]
; ["011100" ; "c"]
; ["011101" ; "d"]
; ["011110" ; "e"]
; ["011111" ; "f"]
; ["100000" ; "g"]
; ["100001" ; "h"]
; ["100010" ; "i"]
; ["100011" ; "j"]
; ["100100" ; "k"]
; ["100101" ; "l"]
; ["100110" ; "m"]
; ["100111" ; "n"]
; ["101000" ; "o"]
; ["101001" ; "p"]
; ["101010" ; "q"]
; ["101011" ; "r"]
; ["101100" ; "s"]
; ["101101" ; "t"]
; ["101110" ; "u"]
; ["101111" ; "v"]
; ["110000" ; "w"]
; ["110001" ; "x"]
; ["110010" ; "y"]
; ["110011" ; "z"]
; ["110100" ; "0"]
; ["110101" ; "1"]
; ["110110" ; "2"]
; ["110111" ; "3"]
; ["111000" ; "4"]
; ["111001" ; "5"]
; ["111010" ; "6"]
; ["111011" ; "7"]
; ["111100" ; "8"]
; ["111101" ; "9"]
; ["111110" ; "+"]
; ["111111" ; "/"]

 )
)//List
		;¢n = ¢n+ 6 

	] ;
Substitute ( $LIST ; [Char(10) ; ""] ; [Char(13)  ; ""])
 )
;¢Length = Length ( $Base64)
;¢Surplus =Mod ( ¢Length ; 4 )
;$Base64 = $Base64 & If ( ¢Surplus    >   0 ; Left ( "====" ; 4 - ¢Surplus ))

];
$Base64
)