将字母转换为数字(例如,A=0、B=1 等等)

将字母转换为数字(例如,A=0、B=1 等等)

我最近问过相反的问题,并得到了一些非常棒的答案,但刚刚意识到我不确定将字母转换为数字的对应物。

这是我用来将数字转换为字母的代码:

\newcommand\makeAlph[1]{%
\ifcase #1 a\or b\or c\or d\or e\or f\or g\or h\or
i\or j\or k\or l\or m\or n\or o\or p\or q\or r\or
s\or t\or u\or v\or w\or x\or y\or z\fi}

因为看起来\ifcase需要数字,所以我不确定如何调整此代码以接受字母并转换为数字;可能是因为在当前形式下它不能这样做,而且还有另一种解决方案。我查看了各种软件包,但找不到解决方案,但我觉得我再次忽略了一些微妙但简单的东西。

基本上,我想处理 36 个字符的字母表 (a-z0-9),其中 a=0、b=1...8=34、9=35。理想情况下,应该有一些这样的命令,如上例\makeNum{}所示。\makeAlph{}

感谢大家对这个问题和其他问题的指导!很高兴提供更多细节,并深入研究我可能错过的任何资源。干杯!

答案1

您可以使用原语\number生成一个数字(这并不奇怪),并使用`<char>语法获取 的 ASCII 索引<char>。然后您可以使用从参数中\numexpr减去 的索引:`A

\documentclass{article}
\newcommand\makefromAlph[1]{\number\numexpr`#1-`A\relax}
\newcommand\makefromalph[1]{\number\numexpr`#1-`a\relax}
\begin{document}
\makefromAlph{B}--\makefromalph{x}
\end{document}

生产1--23

您还可以使用expl3\int_from_alph:n

\documentclass{article}
\ExplSyntaxOn
\NewExpandableDocumentCommand \makefromAlph { m }
  { \int_eval:n { \int_from_alph:n {#1} - 1 } }
\ExplSyntaxOff
\begin{document}
\typeout{\makefromAlph{B}--\makefromAlph{x}}
\end{document}

产生相同的结果1--23。请注意,此处的相同结果\int_from_alph:n可理解大写字母和小写字母。

还要注意,两个版本都没有检查输入的有效性。


A-Z它们映射到0-25很容易,因为它们在 ASCII 表中是连续的,但0-9在那里添加字符有点棘手(当然,这并非不可能)。您可以像 Steven 的回答中那样进行一对一映射,这可能更易于编码(并且可能更快,具体取决于您如何实现它),或者您可以编写一个范围。

在下面的代码中,输入的数字扩展\makealphauxA或一起传递给a,分别用于大写和小写版本。然后将数字与`0和进行比较`9,如果在范围内,则将其计算为 以#1-`0+26给出您期望的结果,否则将其计算为#1-`A(或#1-`a)。以下代码的输出为1--23--26--35

\documentclass{article}
\newcommand\makefromAlph[1]{\expandafter\makealphaux\number`#1;A}
\newcommand\makefromalph[1]{\expandafter\makealphaux\number`#1;a}
\def\makealphaux#1;#2{%
  \number\numexpr#1-%
  \ifnum0%
      \ifnum`0>#1    \else 1\fi
      \ifnum   #1>`9 \else 1\fi
      =11 %
    `0+26%
  \else
    `#2%
  \fi\relax}
\begin{document}
\makefromAlph{B}--\makefromalph{x}--\makefromalph{0}--\makefromalph{9}
\end{document}

或者expl3

\documentclass{article}
\ExplSyntaxOn
\NewExpandableDocumentCommand \makefromAlph { m }
  {
    \exp_args:Nff \__troutman_from_alph_aux:nn
      { \int_eval:n { \int_from_alph:n {#1} } }
      { \int_eval:n { \int_from_alph:n { 0 } } }
  }
\cs_new:Npn \__troutman_from_alph_aux:nn #1#2
  {
    \int_compare:nTF { 0 <= #1-#2 <= 9 }
      { \int_eval:n { #1-#2 + 26 } }
      { \int_eval:n { #1-1 } }
  }
\ExplSyntaxOff
\begin{document}
\makefromAlph{B}--\makefromAlph{x}--\makefromAlph{0}--\makefromAlph{9}
\end{document}

答案2

一种使用 的方法\tokcycle。当然,调用是不可扩展的,但生成的标记列表是可扩展的。

这种方法的一个有趣之处在于,任何未重新映射的符号都会保留其原始形式。因此,大写字母和标点符号将不经改变地通过环境。

\documentclass{article}
\usepackage{tokcycle}
\tokcycleenvironment\remaptext
    {\addcytoks[x]{\tcremap{##1}}}
    {\processtoks{##1}}
    {\addcytoks{##1}}
    {\addcytoks{##1}}
\newcommand*\tcmapto[2]{\expandafter\def\csname tcmapto#1\endcsname{#2}}
\newcommand*\tcremap[1]{\ifcsname tcmapto#1\endcsname
  \csname tcmapto#1\expandafter\endcsname\else\expandafter#1\fi}
\tcmapto a{0}   \tcmapto b{1}   \tcmapto c{2}   \tcmapto d{3}   
\tcmapto e{4}   \tcmapto f{5}   \tcmapto g{6}   \tcmapto h{7}
\tcmapto i{8}   \tcmapto j{9}   \tcmapto k{10}  \tcmapto l{11}
\tcmapto m{12}  \tcmapto n{13}  \tcmapto o{14}  \tcmapto p{15}
\tcmapto q{16}  \tcmapto r{17}  \tcmapto s{18}  \tcmapto t{19}
\tcmapto u{20}  \tcmapto v{21}  \tcmapto w{22}  \tcmapto x{23}
\tcmapto y{24}  \tcmapto z{25}  \tcmapto 0{26}  \tcmapto 1{27}
\tcmapto 2{28}  \tcmapto 3{29}  \tcmapto 4{30}  \tcmapto 5{31}
\tcmapto 6{32}  \tcmapto 7{33}  \tcmapto 8{34}  \tcmapto 9{35}
\begin{document}
\remaptext a b c, l m n, z 0 1, 7 8 9. ABC\endremaptext

Also retained in cytoks token list:\\
\detokenize\expandafter{\the\cytoks}
\end{document}

在此处输入图片描述

下面是它的宏版本,它不会立即打印出结果,而是将其保留在\cytoks标记列表中:

\documentclass{article}
\usepackage{tokcycle}
\newcommand\Remaptext[1]{\tokcycle
    {\addcytoks[x]{\tcremap{##1}}}
    {\processtoks{##1}}
    {\addcytoks{##1}}
    {\addcytoks{##1}}{#1}}
\newcommand*\tcmapto[2]{\expandafter\def\csname tcmapto#1\endcsname{#2}}
\newcommand*\tcremap[1]{\ifcsname tcmapto#1\endcsname
  \csname tcmapto#1\expandafter\endcsname\else\expandafter#1\fi}
\tcmapto a{0}   \tcmapto b{1}   \tcmapto c{2}   \tcmapto d{3}   
\tcmapto e{4}   \tcmapto f{5}   \tcmapto g{6}   \tcmapto h{7}
\tcmapto i{8}   \tcmapto j{9}   \tcmapto k{10}  \tcmapto l{11}
\tcmapto m{12}  \tcmapto n{13}  \tcmapto o{14}  \tcmapto p{15}
\tcmapto q{16}  \tcmapto r{17}  \tcmapto s{18}  \tcmapto t{19}
\tcmapto u{20}  \tcmapto v{21}  \tcmapto w{22}  \tcmapto x{23}
\tcmapto y{24}  \tcmapto z{25}  \tcmapto 0{26}  \tcmapto 1{27}
\tcmapto 2{28}  \tcmapto 3{29}  \tcmapto 4{30}  \tcmapto 5{31}
\tcmapto 6{32}  \tcmapto 7{33}  \tcmapto 8{34}  \tcmapto 9{35}
\begin{document}
\Remaptext{a b c, l m n, z 0 1, 7 8 9. ABC}

Retained in cytoks token list:\\
\the\cytoks
\end{document}

答案3

您可以使用以下方式访问字母“a”的字符代码

`a

所以解决方案很简单:

\documentclass{article}

\ExplSyntaxOn

\NewExpandableDocumentCommand{\makeAlph}{m}
 {
  \int_compare:nTF { `a <= `#1 <= `z }
   {% a letter
    \int_eval:n { `#1 - `a }
   }
   {% a digit
    \int_eval:n { `#1 - `0 + 26 }
   }
 }

\ExplSyntaxOff

\begin{document}

\makeAlph{a}

\makeAlph{b}

\makeAlph{x}

\makeAlph{z}

\makeAlph{0}

\makeAlph{9}

\end{document}

在此处输入图片描述

答案4

由于 30000 个字符的限制,我需要分成两个答案。

这是我的第二个回答。

(这第二个答案第一个答案

如果你想点赞,请点赞只有一个两个答案中的任意一个。这可以防止不公平的声誉获取。如果您想反对,请投票给您想要反对的任何答案。


\makeNum可以放宽 第一个参数(表示要转换的字符标记)与标准类别代码制度的绑定,例如,通过定义\makeNuminner类似于\makeNum我的示例中的宏第一个答案和一个宏\makeNumfork,但两个宏都通过一个临时宏来读取定界符,同时将组内定界字符的 catcode 临时切换到 12(其他),关闭该组并定义宏,并定义在将其传递给之前\makeNum应用于\string第一个参数\makeNuminner- 但请注意,任何 catcode 10(空格)的字符都将被标记为显式空格标记,即类别代码 10(空格)和字符代码 32(!!!)的显式字符标记;\string在任何情况下应用于这样的标记都会产生一个显式的空间标记。因此,与其他答案中提出的方法一样,如果要转换的字符的 catcode 切换为 10(空格)(或某个值,这意味着在 .tex-input-file 中遇到相应字符时根本不会创建任何标记),则此答案中的方法不起作用。

\makeNum的应用\string意味着可以通过(临时)为整数参数分配一个负值\makeNum来欺骗它,使其不仅接受字符标记,还可以接受单字母控制序列标记\a.. \z\A.. \Z\0.. 。\9\escapechar

\errorcontextlines=10000
\documentclass{article}

\makeatletter
%
\newcommand\makeNum[1]{\expandafter\innermakeNum\expandafter{\string#1}}%
%
% ======================================================================
% Step 1: Open up a new group/local scope:
% ======================================================================
\begingroup
% ======================================================================
% Step 2: Define a one-letter-scratch-macro \X to close the group and 
%         to define the macros \innermakeNum, \makeNumfork and 
%         \gobbletoexclam from its arguments (which will be
%         read/tokenized under temporarily changed catcode-régime):
% ======================================================================
\def\X#1#2#3{%
  %------------------------------
  \endgroup
  %------------------------------
  \newcommand\innermakeNum[2]{%
    % Test if ##1 contains exclamation-mark:
    \ifcat$\detokenize\expandafter{\gobbletoexclam##1#3}$%
    \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
    {%
      % ##1 does not contain exclamation-mark:
      \makeNumfork#1%
      #3#3#3#3%
    }{%
      % ##1 does contain exclamation-mark -> argument s.th. else with exclamtion-mark:
      ##2%
    }%
  }%
  %------------------------------
  \@ifdefinable\makeNumfork{%
    \long\def\makeNumfork##1#2##2##3#3#3#3#3{##2}%
  }%
  %------------------------------
  \@ifdefinable\gobbletoexclam{\long\def\gobbletoexclam##1#3{}}%
  %------------------------------
}%
% ======================================================================
% Step 3: Temporarily change the catcode-régime:
% ======================================================================
\def\@makeotherrecursion#1{%
  \ifx\X#1\else\catcode`#1=12\relax\expandafter\@makeotherrecursion\fi
}%
\@makeotherrecursion !abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\X%
% ======================================================================
% Step 4: Call the scratch-macro \X. The scratch-macro \X has TeX
%         - read and tokenize the arguments under temporarily changed
%           catcode-régime.
%         - close the group/local scope and thus annihilate all local
%           assignments like macro-definitions and catcode-changes that 
%           took place within that scope. (The scratch-macro \X will be
%           annihilated/undefined, too.)
%         - define \innermakeNum, \makeNumfork and \gobbletoexclam
%           from the arguments.
% ======================================================================
\X{%
  !#1!a!b!c!d!e!f!g!h!i!j!k!l!m!n!o!p!q!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!H!I!J!K!L!M!N!O!P!Q!R!S!T!U!V!W!X!Y!Z!0!1!2!3!4!5!6!#1!8!9!{33}%
  !!a!b!c!d!e!f!g!h!i!j!k!l!m!n!o!p!q!r!s!t!u!v!w!x!y!z!A!B!C!D!E!F!G!H!I!J!K!L!M!N!O!P!Q!R!S!T!U!V!W!X!Y!Z!0!1!2!3!4!5!6!7!#1!9!{34}%
  !!a!b!c!d!e!f!g!h!i!j!k!l!m!n!o!p!q!r!s!t!u!v!w!x!y!z!A!B!C!D!E!F!G!H!I!J!K!L!M!N!O!P!Q!R!S!T!U!V!W!X!Y!Z!0!1!2!3!4!5!6!7!8!#1!{35}%
  !!a!b!c!d!e!f!g!h!i!j!k!l!m!n!o!p!q!r!s!t!u!v!w!x!y!z!A!B!C!D!E!F!G!H!I!J!K!L!M!N!O!P!Q!R!S!T!U!V!W!X!Y!Z!0!1!2!3!4!5!6!7!8!9!{#2}% argument s.th. else without exclamtion-mark
}{%
  !!a!b!c!d!e!f!g!h!i!j!k!l!m!n!o!p!q!r!s!t!u!v!w!x!y!z!%
  A!B!C!D!E!F!G!H!I!J!K!L!M!N!O!P!Q!R!S!T!U!V!W!X!Y!Z!%
  0!1!2!3!4!5!6!7!8!9!%
}{!}%
% \X does \endgroup and defines \innermakeNum, \makeNumfork and \gobbletoexclam.
%
% An error-message-command:
\newcommand\makeNumerrordefault{%
  %\PackageError{Package-Name}{Invalid argument for \string\makeNum}{Only values a-z, 0-9 are allowed!}%
  \GenericError{(macro \string\makeNum)\@spaces \@spaces \@spaces \@spaces }%
               {macro \string\makeNum Error: Invalid argument for \string\makeNum}%
               {See the comments for explanation.}%
               {Only values a-z, A-Z, 0-9 are allowed!}%
}%
\makeatother

\begin{document}

\vspace*{-4cm}%
\enlargethispage{1cm}%
\footnotesize

\noindent
\verb|\makeNum{a}{\makeNumerrordefault}| yields: \makeNum{a}{\makeNumerrordefault}\\
\verb|\makeNum{A}{\makeNumerrordefault}| yields: \makeNum{A}{\makeNumerrordefault}\\
\verb|\makeNum{b}{\makeNumerrordefault}| yields: \makeNum{b}{\makeNumerrordefault}\\
\verb|\makeNum{B}{\makeNumerrordefault}| yields: \makeNum{B}{\makeNumerrordefault}\\
\verb|\makeNum{c}{\makeNumerrordefault}| yields: \makeNum{c}{\makeNumerrordefault}\\
\verb|\makeNum{C}{\makeNumerrordefault}| yields: \makeNum{C}{\makeNumerrordefault}\\
\verb|\makeNum{d}{\makeNumerrordefault}| yields: \makeNum{d}{\makeNumerrordefault}\\
\verb|\makeNum{D}{\makeNumerrordefault}| yields: \makeNum{D}{\makeNumerrordefault}\\
\verb|\makeNum{e}{\makeNumerrordefault}| yields: \makeNum{e}{\makeNumerrordefault}\\
\verb|\makeNum{E}{\makeNumerrordefault}| yields: \makeNum{E}{\makeNumerrordefault}\\
\verb|\makeNum{f}{\makeNumerrordefault}| yields: \makeNum{f}{\makeNumerrordefault}\\
\verb|\makeNum{F}{\makeNumerrordefault}| yields: \makeNum{F}{\makeNumerrordefault}\\
\verb|\makeNum{g}{\makeNumerrordefault}| yields: \makeNum{g}{\makeNumerrordefault}\\
\verb|\makeNum{G}{\makeNumerrordefault}| yields: \makeNum{G}{\makeNumerrordefault}\\
\verb|\makeNum{h}{\makeNumerrordefault}| yields: \makeNum{h}{\makeNumerrordefault}\\
\verb|\makeNum{H}{\makeNumerrordefault}| yields: \makeNum{H}{\makeNumerrordefault}\\
\verb|\makeNum{i}{\makeNumerrordefault}| yields: \makeNum{i}{\makeNumerrordefault}\\
\verb|\makeNum{I}{\makeNumerrordefault}| yields: \makeNum{I}{\makeNumerrordefault}\\
\verb|\makeNum{j}{\makeNumerrordefault}| yields: \makeNum{j}{\makeNumerrordefault}\\
\verb|\makeNum{J}{\makeNumerrordefault}| yields: \makeNum{J}{\makeNumerrordefault}\\
\verb|\makeNum{k}{\makeNumerrordefault}| yields: \makeNum{k}{\makeNumerrordefault}\\
\verb|\makeNum{K}{\makeNumerrordefault}| yields: \makeNum{K}{\makeNumerrordefault}\\
\verb|\makeNum{l}{\makeNumerrordefault}| yields: \makeNum{l}{\makeNumerrordefault}\\
\verb|\makeNum{L}{\makeNumerrordefault}| yields: \makeNum{L}{\makeNumerrordefault}\\
\verb|\makeNum{m}{\makeNumerrordefault}| yields: \makeNum{m}{\makeNumerrordefault}\\
\verb|\makeNum{M}{\makeNumerrordefault}| yields: \makeNum{M}{\makeNumerrordefault}\\
\verb|\makeNum{n}{\makeNumerrordefault}| yields: \makeNum{n}{\makeNumerrordefault}\\
\verb|\makeNum{N}{\makeNumerrordefault}| yields: \makeNum{N}{\makeNumerrordefault}\\
\verb|\makeNum{o}{\makeNumerrordefault}| yields: \makeNum{o}{\makeNumerrordefault}\\
\verb|\makeNum{O}{\makeNumerrordefault}| yields: \makeNum{O}{\makeNumerrordefault}\\
\verb|\makeNum{p}{\makeNumerrordefault}| yields: \makeNum{p}{\makeNumerrordefault}\\
\verb|\makeNum{P}{\makeNumerrordefault}| yields: \makeNum{P}{\makeNumerrordefault}\\
\verb|\makeNum{q}{\makeNumerrordefault}| yields: \makeNum{q}{\makeNumerrordefault}\\
\verb|\makeNum{Q}{\makeNumerrordefault}| yields: \makeNum{Q}{\makeNumerrordefault}\\
\verb|\makeNum{r}{\makeNumerrordefault}| yields: \makeNum{r}{\makeNumerrordefault}\\
\verb|\makeNum{R}{\makeNumerrordefault}| yields: \makeNum{R}{\makeNumerrordefault}\\
\verb|\makeNum{s}{\makeNumerrordefault}| yields: \makeNum{s}{\makeNumerrordefault}\\
\verb|\makeNum{S}{\makeNumerrordefault}| yields: \makeNum{S}{\makeNumerrordefault}\\
\verb|\makeNum{t}{\makeNumerrordefault}| yields: \makeNum{t}{\makeNumerrordefault}\\
\verb|\makeNum{T}{\makeNumerrordefault}| yields: \makeNum{T}{\makeNumerrordefault}\\
\verb|\makeNum{u}{\makeNumerrordefault}| yields: \makeNum{u}{\makeNumerrordefault}\\
\verb|\makeNum{U}{\makeNumerrordefault}| yields: \makeNum{U}{\makeNumerrordefault}\\
\verb|\makeNum{v}{\makeNumerrordefault}| yields: \makeNum{v}{\makeNumerrordefault}\\
\verb|\makeNum{V}{\makeNumerrordefault}| yields: \makeNum{V}{\makeNumerrordefault}\\
\verb|\makeNum{w}{\makeNumerrordefault}| yields: \makeNum{w}{\makeNumerrordefault}\\
\verb|\makeNum{W}{\makeNumerrordefault}| yields: \makeNum{W}{\makeNumerrordefault}\\
\verb|\makeNum{x}{\makeNumerrordefault}| yields: \makeNum{x}{\makeNumerrordefault}\\
\verb|\makeNum{X}{\makeNumerrordefault}| yields: \makeNum{X}{\makeNumerrordefault}\\
\verb|\makeNum{y}{\makeNumerrordefault}| yields: \makeNum{y}{\makeNumerrordefault}\\
\verb|\makeNum{Y}{\makeNumerrordefault}| yields: \makeNum{Y}{\makeNumerrordefault}\\
\verb|\makeNum{z}{\makeNumerrordefault}| yields: \makeNum{z}{\makeNumerrordefault}\\
\verb|\makeNum{Z}{\makeNumerrordefault}| yields: \makeNum{Z}{\makeNumerrordefault}\\
\verb|\makeNum{0}{\makeNumerrordefault}| yields: \makeNum{0}{\makeNumerrordefault}\\
\verb|\makeNum{1}{\makeNumerrordefault}| yields: \makeNum{1}{\makeNumerrordefault}\\
\verb|\makeNum{2}{\makeNumerrordefault}| yields: \makeNum{2}{\makeNumerrordefault}\\
\verb|\makeNum{3}{\makeNumerrordefault}| yields: \makeNum{3}{\makeNumerrordefault}\\
\verb|\makeNum{4}{\makeNumerrordefault}| yields: \makeNum{4}{\makeNumerrordefault}\\
\verb|\makeNum{5}{\makeNumerrordefault}| yields: \makeNum{5}{\makeNumerrordefault}\\
\verb|\makeNum{6}{\makeNumerrordefault}| yields: \makeNum{6}{\makeNumerrordefault}\\
\verb|\makeNum{7}{\makeNumerrordefault}| yields: \makeNum{7}{\makeNumerrordefault}\\
\verb|\makeNum{8}{\makeNumerrordefault}| yields: \makeNum{8}{\makeNumerrordefault}\\
\verb|\makeNum{9}{\makeNumerrordefault}| yields: \makeNum{9}{\makeNumerrordefault}\\
% \makeNumerrordefault delivers an error-message. Instead we want the phrase "Error-Tokens".
% \verb|\makeNum{&}{\makeNumerrordefault}| yields: \makeNum{&}{\makeNumerrordefault}\\
\verb|\makeNum{&}{Error-Tokens.}| yields: \makeNum{&}{Error-Tokens.}\\
% \verb|\makeNum{What?}{\makeNumerrordefault}| yields: \makeNum{What?}{\makeNumerrordefault}\\
\verb|\makeNum{What?}{Error-Tokens.}| yields: \makeNum{What?}{Error-Tokens.}\\
% \verb|\makeNum{!a!b}{\makeNumerrordefault}| yields: \makeNum{!a!b}{\makeNumerrordefault}\\
\verb|\makeNum{!a!b}{Error-Tokens.}| yields: \makeNum{!a!b}{Error-Tokens.}\\
\verb|\catcode`\w=7 \catcode`\5=11|\\
\verb|\makeNum{w}{\makeNumerrordefault}| yields: \begingroup\catcode`\w=7 \makeNum{w}{\makeNumerrordefault}\endgroup\\
\verb|\makeNum{5}{\makeNumerrordefault}| yields: \begingroup\catcode`\5=11 \makeNum{5}{\makeNumerrordefault}\endgroup\\
\verb|\escapechar=-1|\\
\verb|\makeNum{\V}{\makeNumerrordefault}| yields: \begingroup\escapechar=-1 \makeNum{\V}{\makeNumerrordefault}\endgroup

\end{document}

在此处输入图片描述


由于 30000 个字符的限制,我需要分成两个答案。

这是我的第二个回答。

(这第二个答案第一个答案

相关内容