Custom Number Base Converter

MATL, 2 bytes

Za

Try it online!
All test cases.

For the Za lord!


R, 124 bytes

function(n,s,t,T=L(t),N=(match(!n,!s)-1)%*%L(s)^(L(n):1-1))intToUtf8((!t)[N%/%T^rev(0:log(N,T))%%T+1])
"!"=utf8ToInt
L=nchar

Try it online!

Ugh, this was a doozy. I use the typical base conversion tricks for R, but string manipulations in R are still messy!


APL (Dyalog Unicode), 22 bytes

Anonymous infix lambda. Takes InputFormat as left argument and OutputFormat as right argument, and prompts for Number from stdin. Assumes ⎕IO (Index Origin) to be 0, which is default on many systems.

{⍵[(≢⍵)⊥⍣¯1⊢(≢⍺)⊥⍺⍳⎕]}

Try it online!

{} "dfn"; is left argument, is right argument
(mnemonic: left and right ends of the Greek alphabet)

⍵[] index the output format with the following:

   prompt for input

  ⍺⍳ɩndices of those characters in the input format

  ()⊥ evaluate as being in the following base:

   ≢⍺ the length of the input format

   yield that (separates ¯1 from (≢⍺))

  ()⊥⍣¯1 convert to the following base:

  ≢⍺ the length of the output format