I have a string in which a special character is treated as the separator. For example, str={aA|B|b|Ca|XYzz}
, where "|"
is the separator. Then I want to count the numbers of characters delimited by those "|"
. It should produce {2,1,1,2,4}
as the result for the given example. I can think of using a loop, but what would be a simpler way to do that?
$\begingroup$
$\endgroup$
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
StringLength /@ StringSplit["aA|B|b|Ca|XYzz", "|"]
{2, 1, 1, 2, 4}