如何从十六进制数数组中递增最大的十六进制数?我对十六进制的了解有些参差不齐,因此我们将不胜感激。老实说,我不知道这些数字是否是十六进制的,因为它们前面有一个“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”,这似乎是 Adobe 为您尝试解析的格式指定的名称。
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 页上,您可以找到有关 Adobe 如何为 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/