如何提取字符串中字符的位置?我有以下列,其中包含字符字符串,例如點或字符(無數字和特殊字符)。
我想生成一個列,列出不是點的字符的位置。 請參閱下面的示例。
我可以在 JMP 中使用任何公式或腳本嗎?
·cgaagt··a············2,3,4,5,6,7,10
··t·a··············c·· 3,5,19
············································
數據表Re: 如何提取字符在字符串中的位置?我認為您將不得不編寫腳本。
- 將字符串轉換為列表單詞(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)) = {};Re: 如何提取字符在字符串中的位置?展開@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 );