如何拆分多个单词值并按字母顺序重新排列它们我有一列带有两个字母缩写的字符值。 一些是单个值,另一些是用定界符“ /”分隔的多个值。 问题在于多值值不是按字母顺序排列的。
我想遍历每一行并拆分多值,然后按字母顺序重新排列它们,然后在“新列”中插入新的“值”。 单个值应该只是“复制”,而空值则留为空值。
这让我感到头疼,我将不胜感激任何建议指针或阅读列表,以帮助我解决此问题。
谢谢!
当前数据新数据
AB AB
光盘
EF EF
CD / AB AB / CD
空null
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])),
),
);脚本编写回复:如何拆分多字值并按字母顺序重新排列这是一个适用于示例数据表的公式。附带的是已应用公式的数据表
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]
);
)回复:如何拆分多字值并按字母顺序重新排列我很少能改善@txnelson ,但我可以将其简化为一行公式:
Concat Items( Sort List( Words( :Current data, "/" ) ), "/" )
话()通过使用“ /”作为分隔符将列分成单词,从而创建单词列表。
排序清单()按字母顺序对列表进行排序
Concat物品()使用“ /”将列表中的项目合并为单个字符串,以分隔项目。

回复:如何拆分多字值并按字母顺序重新排列非常非常棒回复:如何拆分多字值并按字母顺序重新排列亲@txnelson和@杰夫·珀金森非常感谢您的回答; 0ne是关于循环的一堂好课,而另一则是令人困惑的单线学习。
我将两者都添加到我的JSL包中。
最好的祝福。
回复:如何拆分多字值并按字母顺序重新排列除了分段和排序外,此公式还会在分段后添加和删除重复的值,并仅保留不重复的字段吗?

最好的祝福。
回复:如何拆分多字值并按字母顺序重新排列否,指定的解决方案都不会删除重复项。该要求不是原始请求的一部分。
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;