|
发表于 2017-9-5 14:01:58
|
显示全部楼层
提供一个笨办法,如下代码:
source_txt="100101001010111110101111111000000010101010101001010001010101111111"
first_pos = end_pos = 0
i=1
return_vector=""
ch=""
while (i < nchar(source_txt))
{
ch=substr(source_txt,i,i)
first_pos = i
end_pos = i
while (ch == substr(source_txt,end_pos+1,end_pos+1))
{
end_pos = end_pos + 1
}
return_vector=c(return_vector,substr(source_txt,first_pos,end_pos))
i = end_pos+1
}
return_vector=return_vector[-1] |
|