Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
issue in email slicer
#1
Hello,
I am beginner and I am practicing on how to create a program for email slicer. I have created until the domain name is extracted and for the second part, I am unable to. Kindly help.

string = "[email protected]"
LengthofString = len(string)
for i in range(LengthofString):
    if string[i]=='@':
        break
    else:
        print(string[i], end="")
for i in range(LengthofString):
    if string[i]=='@':
        i = i + 1
        print(string[I])
Reply
#2
Well, the problem with the second loop is that it will only work for the character immediately after the "@". There are two better and easier ways to do this.

  1. string = "[email protected]"
    split = string.find("@")
    print("User:", string[:split])
    print("Host:", string[split:])
  2. string = "[email protected]"
    split = string.split("@")
    print("User:", split[0])
    print("Host:", split[1])
Reply
#3
Hi,
Thank you for the reply but I just used the same code with three extra lines.

print("***********Email Slicer**************")
email="[email protected]"
LengthoftheEmail= len(email)
print(LengthoftheEmail)
temp = 0
for i in range(LengthoftheEmail):
    if email[i] == '@':
        temp = i
        break
    else:
        print(email[i], end="")
print("")
for i in range(temp + 1,LengthoftheEmail):
    print(email[i], end="")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  An email with inline jpg cannot be read by all email clients fpiraneo 4 3,931 Feb-25-2018, 07:17 PM
Last Post: fpiraneo
  Email - Send email using Windows Live Mail cyberzen 2 5,872 Apr-13-2017, 03:14 AM
Last Post: cyberzen

Forum Jump:

User Panel Messages

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