简体   繁体   English

如何在Spotfire中从十六进制字符串创建整数列?

[英]How can I create integer columns from hex strings in Spotfire?

I am importing a csv-file containing a data column with semicolon separated bytes in hexadecimal format like this: 我正在导入一个csv文件,该文件包含一个数据列,该数据列用分号分隔的十六进制格式的字节,如下所示:

06;03;58;1C;05;F5;D2;70;05;F5;DF;...

(Yes, this is all one column in the comma separated file..) (是的,这是逗号分隔文件中的所有列。)

I would like to parse this column into a number of columns with 32-bit values and convert them to decimal: 我想将此列解析为具有32位值的许多列,并将它们转换为十进制:

06;03;58;1C -> 0x0603581C -> 100882460
05;F5;D2;70 -> 0x05F5D270 -> 99996272 ...

Here is one of my first (futile) attempts to create the first column: 这是我第一次(徒劳的)创建第一列的尝试:

Integer(Concatenate("0x",
    Mid([data], 1, 2), 
    Mid([data], 4, 2), 
    Mid([data], 7, 2), 
    Mid([data], 10, 2)))

Any suggestions on how to accomplish this? 关于如何做到这一点的任何建议? I am trying to avoid the extra step of pre-processing the csv-file in Excel using this very similar calculation: 我试图避免使用此非常相似的计算方法在Excel中预处理csv文件的额外步骤:

HEX2DEC(CONCATENATE(
    MID($M2,1,2),
    MID($M2,4,2),
    MID($M2,7,2),
    MID($M2,10,2)))

The easiest way is probably to use either IronPython or the R interface. 最简单的方法可能是使用IronPython或R接口。 However, here's a version using just calculated columns (quite ugly, but gets the job done): 但是,这是一个仅使用计算列的版本(非常丑陋,但是可以完成工作):

  • extract the one-character substring for pos 1, 2, ... 提取pos 1、2 ...的单字符子字符串
  • replace each character with its numeric value, ie 'A' -> '10', 'B' -> '11', ... 将每个字符替换为其数值,即'A'->'10','B'->'11',...
  • convert it to an integer Int1, Int2, ... 将其转换为整数Int1,Int2,...
  • compute the resulting value as ((Int1*16) + Int2)*16 + ... 将结果值计算为((Int1*16) + Int2)*16 + ...

Here are the column expressions for the calculated columns (I only did the first two characters): 这是计算列的列表达式(我只做前两个字符):

Int1 INT1

Integer(
  Substitute(
    Substitute(
     Substitute(
       Substitute(
         Substitute(
           Substitute(
             Mid([Input],1,1),
             "A","10"),
           "B","11"),
         "C","12"),
       "D","13"),
   "E","14"),
 "F","15"))

Int2 INT2

Integer(
  Substitute(
    Substitute(
     Substitute(
       Substitute(
         Substitute(
           Substitute(
             Mid([Input],2,1),
             "A","10"),
           "B","11"),
         "C","12"),
       "D","13"),
   "E","14"),
 "F","15"))

Result 结果

Integer(([Int1]*16) + [Int2])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用IronPython脚本(最好使用外部名称)在Spotfire中创建计算列? - How can I create a Calculated Column in Spotfire with IronPython script (preferably using External Name)? 如何使用IronPython从Spotfire中的表的所有列中获取值 - How to get values from all the columns of the table in Spotfire using IronPython 如何将Spotfire dxp文件从版本6转换为旧版本,即5.5? - How can I convert a Spotfire dxp file from version 6 to an older version, i.e. 5.5? 如何在Spotfire中使用IronPython获取列的外部名称? - How can I get the externalname of a column using IronPython in Spotfire? 如何在 Spotfire 中提取拟合线斜率系数? - How can I extract fitted line slope coefficients in Spotfire? Spotfire组合图表-如何两次过滤同一图表? - Spotfire Combination Chart - how can I filter the same chart twice? 如何使用 Iron python 在 Spotfire 中创建多选(动态选择列)仪表板 - How to create multiselect(dynamic selection of columns) dashboard in spotfire using iron python 如何根据 IronPython 中的当前用户在 Spotfire 中“隐藏”选项卡? - How can I 'hide' a tab in Spotfire depending on the current user in IronPython? 如何在Spotfire中创建帕累托图 - How to Create a Pareto Plot in Spotfire 如何在Spotfire中更改交叉表的行高 - How can I change the row height of cross table in Spotfire
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM