如何拆分多個單詞值並按字母順序重新排列它們我有一列帶有兩個字母縮寫的字符值。 一些是單個值,另一些是用定界符“ /”分隔的多個值。 問題在於多值值不是按字母順序排列的。
我想遍歷每一行並拆分多值,然後按字母順序重新排列它們,然後在“新列”中插入新的“值”。 單個值應該只是“複製”,而空值則留為空值。
這讓我感到頭疼,我將不勝感激任何建議指針或閱讀列表,以幫助我解決此問題。
謝謝!
當前數據新數據
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;