如何提取字符串中某個字符的位置?我有以下列,其中包含字符字符串,例如點或字符(沒有數字和特殊字符)。
我想生成一個列,列出不是點的字符的位置。 請參閱下面的示例。
我可以在 JMP 中使用任何公式或腳本嗎?
·cgaagt··a···········2,3,4,5,6,7,10
··t·a············c··3,5,19
·····················
高級統計建模自動化和腳本編寫數據探索和可視化回复:如何提取字符串中字符的位置?擴展於@jthi很好的解決方案,我相信處理您的問題的最佳方法是創建一個新列來放置結果。另外,您指出這不僅僅是一個“。”可以用作特殊字符。因此,下面的 JSL 是一個可以處理多個特殊字符的公式,並且還在新列中返回結果。只需創建一個字符列並將公式剪切並粘貼到其中即可。

list_of_chars = Words( :strings, "" );
Substitute Into( list_of_chars, ".", "", "+", "", "/", "" );
charList = As List( Loc Nonmissing( list_of_chars ) );
Substr( Char( charList ), 2, Length( Char( charList ) ) - 2 );
回复:如何提取字符串中字符的位置?我認為你必須編寫腳本。
- 將字符串轉換為列表單詞(str,“”)
- 使用 Substitute 將您不感興趣的所有值替換為空字符串(缺失值)
- 使用 Loc NonMissing 查找非缺失值的索引
Names Default To Here(1);
a = "·cgaagt··a···········";
b = "··t·a·············c··";
c = "·····················";
list_of_chars = Words(a, "");
Substitute Into(list_of_chars, "·", "");
Show(AsList(Loc Nonmissing(list_of_chars)));
a = "··t·a·············c··";
list_of_chars = Words(a, "");
Substitute Into(list_of_chars, "·", "");
Show(AsList(Loc Nonmissing(list_of_chars)));
a = "·····················";
list_of_chars = Words(a, "");
Substitute Into(list_of_chars, "·", "");
Show(AsList(Loc Nonmissing(list_of_chars)));
//As List(Loc Nonmissing(list_of_chars)) = {2, 3, 4, 5, 6, 7, 10};
//As List(Loc Nonmissing(list_of_chars)) = {3, 5, 19};
//As List(Loc Nonmissing(list_of_chars)) = {};