如何拆分多词值并按字母顺序重新排列它们我有一列字符值是两个字母的缩写。 有些是单个值,有些是多个值,由分隔符“/”分隔。 问题是多值的值不是按字母顺序排列的。
我想遍历每一行并拆分多值并按字母顺序重新排列它们并在新列中插入新的“值”。 单个值应该只是“复制”,空值保留为空值。
这超出了我的理解范围,我将不胜感激任何建议指针或阅读列表来帮助我解决这个问题。
谢谢!
当前数据 新数据
AB AB
光盘光盘
英孚英孚
CD/AB AB/CD
空 空
EF/AB/CD AB/CD/EF
col = ("Really | Long | and | Boring | Column | Name");
Vals = As Column (col) << Get Values; // Get Values
dt = New Column ("NewAbs", Character, "Nominal" ); //New column for NEW DATA
rows = N rows (dt); // Total number of rows to iterate
for(i = 1 , i <= rows, i++,
if(rowVal (Contains (Vals[i], "/")), // check if is multi-value i.e. AB/DF
rowVal = Words(Vals[i],"/"); // Words will split multi-values at "/"
sval = Sort List(Eval List(rowVal) ); // sort the character values
For(i = 1, i <= N Items (sVal), i++,
newVal = sVal[i];
conCat = Concat Items ( newVal[i] || "/"|| newVal[i+i])
),
Insert Into (dt, conCat[i]),
if(rowVal (!Contains (Vals[i], "/")), // if is NOT multi-value i.e. AB/DF
Insert Into (dt, rowVal[i])),
),
);脚本回复:如何拆分多词值并按字母顺序重新排列它们这个例子说明了另一种使用字典的方法:
Names Default To Here( 1 );
theList = {"AB", "AB", "CD", "EF"};
theArray = Associative Array( theList );
theNewList = theArray << Get Keys;
Show( theNewList );回复:如何拆分多词值并按字母顺序重新排列它们不,指定的解决方案都不会删除重复项。该要求不是原始请求的一部分。
Contains() 函数能够检查列表中的项目以查看是否找到匹配项。我经常使用它。
Names Default To Here( 1 );
theList = {"AB", "AB", "CD", "EF"};
x = {};
Insert Into( x, theList[1] );
For( i = 2, i <= N Items( theList ), i++,
If( Contains( x, theList[i] ) == 0,
Insert Into( x, theList[i] )
)
);
show(x);
因此,所要做的就是将此代码放入一个或其他建议的解决方案中。
x = :Current data;
If( Contains( x, "/" ) > 0,
theList = Words( x, "/" );
theList = Sort List( theList );
x = {};
Insert Into( x, theList[1] );
For( i = 2, i <= N Items( theList ), i++,
If( Contains( x, theList[i] ) == 0,
Insert Into( x, theList[i] )
)
);
x = Concat Items( x, "/" );
);
x;回复:如何拆分多词值并按字母顺序重新排列它们这个公式除了切分和排序之外,是否对切分后的重复值进行增减,只保留不重复的字段?如:

此致。
回复:如何拆分多词值并按字母顺序重新排列它们亲爱的@txnelson和@Jeff_Perkinson非常感谢您的回答; 0ne 是关于循环的重要一课,另一个是令人难以置信的单行代码。
我会将两者都添加到我的 JSL 包中。
此致。
回复:如何拆分多词值并按字母顺序重新排列它们非常非常棒回复:如何拆分多词值并按字母顺序重新排列它们我通常无法改进@txnelson ,但我可以将其归结为一行公式:
Concat Items( Sort List( Words( :Current data, "/" ) ), "/" )
字()通过使用“/”作为分隔符将列分解为单词来创建单词列表。
排序列表()按字母顺序排序列表
连接项目()将列表中的项目连接成一个字符串,使用“/”分隔项目。

回复:如何拆分多词值并按字母顺序重新排列它们这是一个适用于您的示例数据表的公式。附上应用公式的数据表
If( Contains( :Current data, "/" ) == 0,
x = :Current data,
i = 1;
theList = {};
While( Word( i, :Current data, "/" ) != "",
Insert Into( theList, Word( i, :Current data, "/" ) );
i++;
);
theList = Sort List( theList );
x = theList[1];
For( i = 2, i <= N Items( theList ), i++,
x = x || "/" || theList[i]
);
)