Movatterモバイル変換
[0]ホーム
Is there a string function that will tell me...
Paul Brianpbrian at demon.net
Thu Apr 19 11:47:36 EDT 2001
Terrence,I do not know of any such in python, but the following may help:import stringdef test(str, sub, occr): #act like fortran AT function z = 0 count = 0 while count < occr: x = string.find(str,sub,z) if x == -1: break else: count = count + 1 z = x + 1 #this should now be index return xs = 'terrence'a = test(s,'e',3)print agives you index of the 3rd 'e'I am vaguely aware of something in re that does what you are after, but Icannot find it.hope it helps..."Terrence Spencer" <terrence at mactexas.com> wrote in messagenews:bYCD6.132818$wx.21739668 at typhoon.austin.rr.com...> In the Foxpro language the is a function called:>> AT(SearchingFor,StringToSearch,Count)>> So if I want to find out what location the 3rd "e" is in the string> "terrence" I would say:>> ?at("e","terrence",3)>> and that would return 7, the location of the 3rd "e".>> Does python have something simular?>> Thanks.>> -->> ---------------------------------------------------------> Terrence P. Spencer> Director of Information Technologies> Municipal Advisory Council of Texas>>
More information about the Python-listmailing list
[8]ページ先頭