javascript - 如何创建和递增 2 位或 3 位十六进制数?

标签 javascript actionscript-3 adobe-indesign

如何从十六进制数数组中递增最大的十六进制数?我对十六进制的了解有些参差不齐,因此我们将不胜感激。老实说,我不知道这些数字是否是十六进制的,因为它们前面有一个“u”,但如果你删除“u”,它们看起来就是那样。这些值来自 InDesign 片段文档。

示例:

var anArray = ["uf9","ufc","u111","u112","u136","u137"]; // actual values

var getUniqueID = getNextHigherNumber(anArray);

function getNextHigherNumber(anArray) {
   // sort array
   // create variable and add one
   // return variable 
   return variable;
}

来自服务器的 XML(查看 Self 和 Source):

<Hyperlink Self="ufc" Name="is a  multiline hyperlink that terminates here" Source="uf9" Visible="false" Highlight="None" Width="Thin" BorderStyle="Solid" Hidden="false" DestinationUniqueKey="1">
    <Properties>
        <BorderColor type="enumeration">Black</BorderColor>
        <Destination type="object">HyperlinkURLDestination/http%3a//test.com#1stMultilineLink/</Destination>
    </Properties>
</Hyperlink>
<Hyperlink Self="u112" Name="hyperlink inline" Source="u111" Visible="false" Highlight="None" Width="Thin" BorderStyle="Solid" Hidden="false" DestinationUniqueKey="2">
    <Properties>
        <BorderColor type="enumeration">Black</BorderColor>
        <Destination type="object">HyperlinkURLDestination/http%3a//test.com</Destination>
    </Properties>
</Hyperlink>
<Hyperlink Self="u137" Name="another multline hyperlink" Source="u136" Visible="false" Highlight="Outline" Width="Thick" BorderStyle="Solid" Hidden="false" DestinationUniqueKey="3">
    <Properties>
        <BorderColor type="enumeration">Purple</BorderColor>
        <Destination type="object">HyperlinkURLDestination/http%3a//google.com#multilinehyperlink</Destination>
    </Properties>
</Hyperlink>

更多背景:

我有一个现有的 XML 文档,它的 ID 看起来像是使用十六进制数字系统,我需要能够为新节点创建一个唯一的 ID。 ID 值看起来类似于 HTML Web 颜色,如“0xFF0000”(红色),但不同之处在于它使用 2 或 3 个字符而不是 6 个,例如“ufc”或“u112”。

我从服务器收到一个 XML 文件,它有节点,每个节点都有一个具有唯一值的 ID(参见上面的 XML 示例)。如果我必须创建一个新的“项目”,我需要为其创建一个尚未使用的唯一 ID。

最佳答案

首先,十六进制只是数字的一种表示。 数字本身保持不变。

Adding 2, 意思是,取这个数的值,加上2的值。 十六进制只是另一种记下数字的方式。

非常感谢您努力弄清楚这些值是什么,但为什么不查看文档来确定呢?

您有一个通过 InDesign 收到或从 InDesign 收到的 XML。 只需搜索它就会向我抛出“IDML”,这似乎是 Adob​​e 为您尝试解析的格式指定的名称。

Adobe 提供了描述这种格式的文档: https://wwwimages2.adobe.com/content/dam/Adobe/en/devnet/indesign/cs55-docs/IDML/idml-specification.pdf

10.1.1 节是关于 Self 属性的:

The Self attribute contains a unique identifier for the elements that contain it. This identifier is used elsewhere in the IDML package to refer to the element, as discussed in the “Object Reference Format” section of this specification. Schema Example 2. Self attribute Self { xsd:string }

如您所见,该值是一个字符串,而不是一个数字。

在第 31 页上,您可以找到有关 Adob​​e 如何为 Self 创建值的说明,包括以下语句:

The only requirement of the value of the Self attribute is that it is unique within the IDML package. If you are writing the IDML yourself, you do not need to observe the above pattern— you can change the value of the Self attribute to anything you want as long as it is unique (within the IDML package) and as long as all references to the element are also changed to match.

关于javascript - 如何创建和递增 2 位或 3 位十六进制数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29197994/

相关文章:

javascript - Angular JS Ng-switch默认状态?

javascript - 在 indesign 脚本中使用 xml 内容标记

javascript - 使用 indesign 中的脚本获取和设置表格中的文本元素

javascript - 如何在 Indesign 中使用 javascript 将图像放置在文本框架中?

javascript - 获取网站词频计数的最佳方法?还是网站的一部分?

javascript - 将变量从悬停传递到悬停

javascript - 当 ReactJS 重新渲染时,预先存在的对象会发生什么?

mysql - 如何在 AS3 中使用 mx.rpc.Responder

xml - 加载 XML 文件时从文本节点的内容中去除前导和尾随空格

actionscript-3 - AS3警告: Class 'Main' does not extend the 'DefineBits' asset base class 'flash.display.Bitmap or flash.display.BitmapData'