You already got an answer to part 1, along these lines:
first=findc(str,'1');
last=findc(str,'1','b');
want=last-first;
For part 2, add one last statement:
if index(substr(str, first, want), '00') then want = .U;
Note that WANT is defined as numeric. So it can't store "unclassified" as its value. But it can store a special missing value (.U) to indicate that it fits into that category.