Python Forum

Full Version: issue in email slicer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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])
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])
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="")