ถ้าส่วนข้อความอยู่ว่าไม่ได้อยู่ในข้อความเป็นภาษาไพธอน
fullstring = "StackAbuse"
substring = "tack"
if fullstring.find(substring) != -1:
print "Found!"
else:
print "Not found!"
ปลั๊กอินสำหรับไพธอน str บรรจุคำ
fullstring = "StackAbuse"
substring = "tack"
if substring in fullstring:
print "Found!"
else:
print "Not found!"
วิธีตรวจสอบว่ามีคำที่เป็นข้อความภาษาไพธอน
>>> str = "Messi is the best soccer player"
>>> "soccer" in str
True
>>> "football" in str
False
ปลั๊กอินสำหรับไพธอนตรวจสอบว่าข้อความในข้อความ
if "blah" not in somestring:
continue
วิธีตรวจสสำหรับส่วนข้อความอยู่ว่าในภาษาไพธอน
def find_string(string,sub_string):
return string.find(sub_string)
#.find() also accounts for multiple occurence of the substring in the given string
ยังไงฉันตรวจสอบว่าเป็นบรรจุข้อความมีเหยื่อที่เป็นคำพูดน่ะเหรอ?
$a = 'Hello world?';
if (strpos($a, 'Hello') !== false) { //PAY ATTENTION TO !==, not !=
echo 'true';
}
if (stripos($a, 'HELLO') !== false) { //Case insensitive
echo 'true';
}