By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

Finding text in a string

P: 1
Expand|Select|Wrap|Line Numbers
  1. import os, string, StringIO
  2.  
  3. results = "lgqgdBddddddoS"
  4. index1 = results.find("B")
  5. index2 = results.find("S")
  6.  
  7. def extract(host, index1, index2):
  8.         return host.split(index1)[-1].split(index2)[0]
how do i go about finding all the text between b and s. thakns
Jan 27 '09 #1
Share this Question
Share on Google+
2 Replies


P: 4
Simple: just type something like
print results[index1+1:index2]

JC
Jan 27 '09 #2

bvdet
Expert Mod 2.5K+
P: 2,851
JCOSTA is correct. It's called slicing (s[i:j]). Slicing can be used on sequence types, including lists, strings, and tuples.
Jan 27 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.