擅长:python、mysql、java
<p>使用<code>index('\x00')</code>获取第一个空字符的索引,并将字符串切片到索引</p>
<pre><code>mystring = "This is my string\x00\x00\x00hi there\x00"
terminator = mystring.index('\x00')
print(mystring[:terminator])
# "This is my string"
</code></pre>
<p>您也可以<code>split()</code>在空字符上</p>
^{pr2}$