How to extract the position of a char in a string?I have the following column, which contains string of char, such as dot or char (no number and special char).
I want to generate a column that list out the position of the char which is not a dot. See an example below.
Is there any formula or script I can use in JMP??
·cgaagt··a··········· 2,3,4,5,6,7,10
··t·a·············c·· 3,5,19
·····················
Data TableRe: How to extract the position of a char in a string?I think you will have to script it.
- Convert the string to a list with Words(str, "")
- Replace all values you aren't interested in with empty string (missing value) by using Substitute
- Use Loc NonMissing to find indices of non missing values
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: How to extract the position of a char in a string?Expanding on @jthi great solution, I believe the best way to handle your issue is to create a new column to place the results in. Also, you indicated that not just a "." might be used as a special character. So the JSL below is a formula that can handle multiple special characters, and also returns the results in a new column. Just create a character column and cut and past the formula into it.

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 );