如何提取字符串中字符的位置?我有以下列,其中包含字符字符串,例如点或字符(无数字和特殊字符)。
我想生成一个列,列出不是点的字符的位置。 请参阅下面的示例。
我可以在 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 );