Python Forum
issue in email slicer - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: issue in email slicer (/thread-27962.html)



issue in email slicer - spalisetty06 - Jun-29-2020

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])



RE: issue in email slicer - stullis - Jun-29-2020

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])



RE: issue in email slicer - spalisetty06 - Jun-30-2020

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="")