这里会显示出您选择的修订版和当前版本之间的差别。
python-basic:string-strstr [2010/06/02 01:18] |
python-basic:string-strstr [2010/06/02 01:18] (当前版本) |
||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== Python 字符串(string) strstr 操作 ====== | ||
+ | strstr是php中的函数: | ||
+ | 返回字符串中某字符串开始处至结束的字符串。 | ||
+ | |||
+ | 语法: string strstr(string haystack, string needle); | ||
+ | |||
+ | 返回值: 字符串 | ||
+ | |||
+ | 函数种类: 资料处理 | ||
+ | |||
+ | 内容说明: | ||
+ | |||
+ | 本函数将 needle 最先出现在 haystack 处起至 haystack 结束的字符串返回。若找不到 needle 则返回 false。 | ||
+ | |||
+ | ===== Python中实现strstr功能===== | ||
+ | 使用字符串的查找函数find能够很容易的实现strstr的功能: | ||
+ | <code python> | ||
+ | sStr1 = 'abcdefg' | ||
+ | sStr2 = 'cde' | ||
+ | start_index = sStr1.find(sStr2) | ||
+ | print sStr1[start_index:] | ||
+ | </code> |