2
$\begingroup$

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?

$\endgroup$
3
$\begingroup$
StringLength /@ StringSplit["aA|B|b|Ca|XYzz", "|"]

{2, 1, 1, 2, 4}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.