Python Forum
str.find() not returning correct index.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
str.find() not returning correct index.
#5
Hmm. I'm not sure what's going on then. I wonder if the file is in some odd encoding that your editor is handling automatically?

If you're looking for the "aHR..." string, then your python program (with a couple tiny updates) works for me. I've saved your upload in a text file.

Output:
$ cat ascii.txt -----ASCII ENCODED DATA------- =aHR0cDovL3d3dy5ib29tbGluZ3MuY29tL2RhdGFiYXNlL2dldEdKTGV2ZWxzMjEucGhw#lvl_dataaHR0cDovL3d3dy5ib29tbGluZ3MuY29tL2RhdGFiYXNlL2dldFNhdmVEYXRhLnBocA==&page=%i&secret=%saHR0cDovL3d3dy5ib29tbGluZ3MuY29tL2RhdGFiYXNlL2dldEdKTWFwUGFja3MyMS5waHA=pack_%igauntlet_%iget_gauntlets&secret=%saHR0cDovL3d3dy5ib29tbGluZ3MuY29tL2RhdGFiYXNlL2dldEdKR2F1bnRsZXRzMjEucGhw&gauntlet=%i_%i&levelID=%i&inc=%i&extras=%i&secret=%s&rs=%i%i%s%i%s%i%s&chk=aHR0cDovL3d3dy5ib29tbGluZ3MuY29tL2RhdGFiYXNlL2Rvd25sb2FkR0pMZXZlbDIyLnBocA==%i,%i,%i,%i,%i,%i,%i,%i&levelID=%i&gameVersion=%i&secret=%sgeometry.ach.rateDiff&levelID=%i&stars=%i&secret=%ssg6pUrt0J58281aHR0cDovL3d3dy5ib29tbGluZ3MuY29tL2RhdGFiYXNlL3JhdGVHSlN0YXJzMjExLnBocA==1128989
And then this program:

b64link = "aHR0cDovL3d3dy5ib29tbGluZ3MuY29tL2RhdGFiYXNlL2Rvd25sb2FkR0pMZXZlbDIyLnBocA=="
with open("ascii.txt", 'r', encoding="ascii") as f:
    t = f.read()
    if(b64link in t):
        location = t.find(b64link)
        print(location)
Generates this output:
Output:
456
That's zero-indexed. If I open the text file in vi and goto 457, that puts me right on the the string.

Obviously we could be trying to decode the base64 bits, but that doesn't seem to be what you're trying to do.
Reply


Messages In This Thread
RE: str.find() not returning correct index. - by bowlofred - Aug-18-2020, 04:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  labels.append(self.classes.index(member.find('name').text)) hobbyist 1 1,946 Dec-15-2021, 01:53 PM
Last Post: deanhystad
  pandas pivot table: How to find count for each group in Index and Column JaneTan 0 3,351 Oct-23-2021, 04:35 AM
Last Post: JaneTan
  Find index value in List Martin2998 3 2,826 May-12-2020, 02:17 PM
Last Post: deanhystad
  How to find something in a list using its index rix 1 1,753 Dec-20-2019, 04:12 PM
Last Post: stullis
  Find index of missing number parthi1705 3 3,171 May-07-2019, 10:52 AM
Last Post: avorane
  Function not returning correct value ActualNoob 3 2,725 Jan-11-2019, 12:35 AM
Last Post: stullis
  How Do I find Index of a character in string? ilcaa72 5 3,779 May-23-2018, 11:44 PM
Last Post: wavic
  find the index of "Annual" in spell_list nikhilkumar 1 5,663 Jul-12-2017, 04:56 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020