ぱっと検索してもプログラム上で変換するコードが見つからなかったので…!
JavaScript version
function convertSalesforceIdFrom15to18(input) {
let addon = "";
for (let block = 0; block < 3; block++) {
let loop = 0;
for (let position = 0; position < 5; position++){
var current=input.charAt(block * 5 + position);
if(current >= "A" && current <= "Z")
loop += 1 << position;
}
addon += "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345".charAt(loop);
}
return `${input}${addon}`;
}
PHP version
function convertSalesforceIdFrom15to18(string $input): string
{
$addon = "";
for ($block = 0; $block < 3; $block++) {
$loop = 0;
for ($position = 0; $position < 5; $position++) {
$index = $block * 5 + $position;
$current = $input[$index];
if ($current >= "A" && $current <= "Z") {
$loop += (1 << $position);
}
}
$checksum_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
$addon .= $checksum_chars[$loop];
}
return $input . $addon;
}
Go version
const checksumChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"
func convertSalesforceIdFrom15to18(input string) string {
var addon string
for block := 0; block < 3; block++ {
loop := 0
for position := 0; position < 5; position++ {
charIndex := block*5 + position
current := input[charIndex]
if current >= 'A' && current <= 'Z' {
loop += 1 << position
}
}
if loop < len(checksumChars) {
addon += string(checksumChars[loop])
}
}
return input + addon
}