Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I parse the string?
#4
Another way
astring = 'FTP://21.105.28.15/abc/test1.txt'
astring2 = 'FTP://21.105.28.15/abc/def/test1.txt'

def remover(astring):
    astring = astring.split('/')
    for index, item in enumerate(astring):
        if item == '':
            astring.remove(item)
        elif index in (0, 1):
            astring.remove(item)
    return '/'.join(astring)

print(remover(astring))
print(remover(astring2))
output
Output:
/abc/test1.txt /abc/def/test1.txt
little adjustment can remove the file at the end as well
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply


Messages In This Thread
How do I parse the string? - by anna17 - Apr-10-2024, 07:07 AM
RE: How do I parse the string? - by Gribouillis - Apr-10-2024, 07:36 AM
RE: How do I parse the string? - by Pedroski55 - Apr-10-2024, 09:40 AM
RE: How do I parse the string? - by menator01 - Apr-10-2024, 10:23 AM
RE: How do I parse the string? - by DeaD_EyE - Apr-10-2024, 10:26 AM
RE: How do I parse the string? - by kakocer - Jan-20-2025, 08:11 PM
RE: How do I parse the string? - by Keville_35 - Jan-21-2025, 05:08 AM
RE: How do I parse the string? - by DeaD_EyE - Jan-21-2025, 12:48 PM
RE: How do I parse the string? - by michaeljordan - Feb-13-2025, 07:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Parse Nested JSON String in Python mmm07 4 2,992 Mar-28-2023, 06:07 PM
Last Post: snippsat
  parse String jaykappy 2 1,630 Dec-23-2022, 07:42 AM
Last Post: praveencqr
  Parse String between 2 Delimiters and add as single list items lastyle 5 4,770 Apr-11-2021, 11:03 PM
Last Post: lastyle

Forum Jump:

User Panel Messages

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