多次计算一个角色

时间:2017-12-01 00:23:41

标签: python micropython

一旦角色在Python中的字符串中多次出现,我想要做的就是打破程序。

这是我得到的输出:

  

B' 30,22,37,293,29,26,55,30D \ r \ n $的GPGSV,3,1,11,01,04,250,03,21,309,24,08,15,200,10 ,20157,7B * \ r \ n $的GPGSV,3,2,11,14,49,062,37,16'       B' 8,W,001328.00,A,A * 70 \ r \ n9,26,55,359,30 * 75 \ r \ n $的GPGSV,3,3,11,27,40,170,38,31,20,022, 14,32,42,094,35 * 4C \ r \ n $的GPGLL,0226.72251,N,0'       B' A * 2E \ r \ n $的GPGGA,001329.00,A,A * 70 \ r \ n $的GPRMC,001329.00,A,0226.72248,N,07635.92031,W,0.008,011217 ,,, A * 64 \ r \ n $的GPVTG ,,Ť...,M,0.008,N,'       B' 2.25,1.08,1.98 * 0D \ r \ n $的GPG1329.00,0226.72248,N,07635.92031,W,1,08,1.08,1769.1,M 9.8,M,* 4C \ r \ n $的GPGSA,A,3,16,32,26,31,14,22,27'

所以我想停止第五次" b'"出现了。

2 个答案:

答案 0 :(得分:0)

您可以尝试正则表达式并捕获组(),

你在寻找这样的东西:

import re
pattern=r"b'[0-9]+"

data="""b'30,22,37,293,29,26,55,30D\r\n$GPGSV,3,1,11,01,04,250,,03,21,309,24,08,15,200,,10,20,157,*7B\r\n$GPGSV,3,2,11,14,49,062,37,16'
b'8,W,001328.00,A,A*70\r\n9,26,55,359,30*75\r\n$GPGSV,3,3,11,27,40,170,38,31,20,022,14,32,42,094,35*4C\r\n$GPGLL,0226.72251,N,0'
b'A*2E\r\n$GPGGA,001329.00,A,A*70\r\n$GPRMC,001329.00,A,0226.72248,N,07635.92031,W,0.008,,011217,,,A*64\r\n$GPVTG,,T,,M,0.008,N,'
b'2.25,1.08,1.98*0D\r\n$GPG1329.00,0226.72248,N,07635.92031,W,1,08,1.08,1769.1,M,9.8,M,,*4C\r\n$GPGSA,A,3,16,32,26,31,14,22,27'"""

all_items=[]
track=[]
for i in data.split(','):
    pr=re.search(pattern,i)
    if len(track)==5:
        break
    else:
        if pr!=None:
            track.append(pr.group())
            all_items.append(pr.group())
        else:
            all_items.append(i)

print(all_items)

如果第二个“b”出现,我们试试而不是5:

all_items=[]
track=[]
for i in data.split(','):
    pr=re.search(pattern,i)
    if len(track)==2:
        break
    else:
        if pr!=None:
            track.append(pr.group())
            all_items.append(pr.group())
        else:
            all_items.append(i)

print(all_items)

输出:

["b'30", '22', '37', '293', '29', '26', '55', '30D\r\n$GPGSV', '3', '1', '11', '01', '04', '250', '', '03', '21', '309', '24', '08', '15', '200', '', '10', '20', '157', '*7B\r\n$GPGSV', '3', '2', '11', '14', '49', '062', '37', "b'8"]

而不是3,你可以在那里替换5。

答案 1 :(得分:0)

react-native init myapp
npm install
yarn add react-native-maps
react-native link react-native-maps