如何拆分多詞值並按字母順序重新排列它們我有一列字符值是兩個字母的縮寫。 有些是單個值,有些是多個值,由分隔符“/”分隔。 問題是多值的值不是按字母順序排列的。
我想遍歷每一行並拆分多值並按字母順序重新排列它們並在新列中插入新的“值”。 單個值應該只是“複製”,空值保留為空值。
這超出了我的理解範圍,我將不勝感激任何建議指針或閱讀列表來幫助我解決這個問題。
謝謝!
當前數據 新數據
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]
);
)