通常我用C寫入#從一行中獲取子字符串
如何剪切字符串? 我有這樣一行:
Line 58: Oct 6 16:58:03 INTEG_245 sia_server[6830]: DbsinkConsumer.cc:262: (D) <video> 07920E: Got msg_idx=28 for evt_id=436752
,我需要削減28?
這是我使用的代碼:
if (str(line).find("msg_idx=") > 0):
msg_id = line[line.index("Got"):line.index("For")]
得到了一個錯誤:
sg_id = line[line.index("Got"):line.index("For")]
ValueError: substring not found
將竭誠爲例子
你試過字符切片? –
嘗試'line.index(「for」)'(小寫'f') –
什麼是字符串切片? –