Text transforming functions

\documentclass{article}
\usepackage{stringstrings}
\newcommand\latinify[1]{%
  \convertchar[q]{#1}{U}{V}%
  \convertchar{\thestring}{W}{VV}%
}
\begin{document}
\def\myphrase{CUSTWINIUS}
\myphrase{} versus \latinify{\myphrase}
\end{document}

enter image description here

And now for some sleight of hand:

\documentclass{article}
\usepackage{stringstrings}
\newcommand\latinify[1]{%
  \encodetoken{\kern}%
  \encodetoken[2]{\footnotesize}%
  \encodetoken[3]{\normalsize}%
  \convertchar[e]{#1}{U}{\footnotesize V\normalsize}%
  \convertchar[e]{\thestring}{W}{V\kern-5pt\footnotesize V\normalsize}%
  \retokenize{\thestring}\thestring%
  \decodetoken{\kern}%
  \decodetoken[2]{\footnotesize}%
  \decodetoken[3]{\normalsize}%
}
\begin{document}
\def\myphrase{UNCLE CUSTWINIUS WABBLEWAUSER}
\myphrase{} versus 

\latinify{\myphrase}
\end{document}

enter image description here


The \replacestrings from OPmac can be used. It is implemented by few lines of TeX code:

\long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
\bgroup \catcode`!=3 \catcode`?=3
\gdef\replacestrings#1#2{\long\def\replacestringsA##1#1##2!{%
   \ifx!##2!\addto\tmpb{##1}\else\addto\tmpb{##1#2}\replacestringsA##2!\fi}%
   \edef\tmpb{\expandafter}\expandafter\replacestringsA\tmpb?#1!%
   \long\def\replacestringsA##1?{\def\tmpb{##1}}\expandafter\replacestringsA\tmpb
}
\egroup

\def\cnvUVW#1{\def\tmpb{#1}%
   \replacestrings{U}{V}\replacestrings{W}{V\kern-.5emV}\tmpb}

\cnvUVW{UNCLE CUSTWINIUS WABBLEWAUSER}

Edit I am surprised that nobody suggested usage of active characters here. I repair it:

\def\adef#1{\catcode`#1=13 \begingroup \lccode`\~=`#1\lowercase{\endgroup\def~}}
\def\setUW{\adef U{V}\adef W{V\kern-.5emV}}

{\setUW UNCLE CUSTWINIUS WABBLEWAUSER}

A pure LuaLaTeX solution: A Lua function (named u2v_w2vv) and a LaTeX macro (named \uvwvv) that invokes the Lua function.

enter image description here

\documentclass{article}

%% Lua-side code
\usepackage{luacode}
\begin{luacode}
function u2v_w2vv ( s )
  s = string.gsub ( s , "U" , "V" )
  s = string.gsub ( s , "W" , "VV" )
  return tex.sprint ( s )
end
\end{luacode}

%% LaTeX-side code
\newcommand\uvwvv[1]{\directlua{u2v_w2vv(\luastring{#1})}}

\begin{document}
UNCLE CUSTWINIUS WABBLEWAUSER vs. 

\uvwvv{UNCLE CUSTWINIUS WABBLEWAUSER}
\end{document}