Jump to content

get name from email address john.smith@dotmail.com


Recommended Posts

Hello AutoIt team,

I got a string saved in an array:

$email[0] = " john.smith@dotmail.com"

and I am trying to copy from  array the firstname and lastname of this email.

and create a variable like:

$name = "john" & " Smith"

I could not find a solution to copy all strings till "." (firstname) and afterwards copy all strings till from "." to "@" (lastname)

 

Maybe I am blind and there is already a function for this :x

 

Best regards

Hendrik

 

Edited by hendrikhe
Link to comment
Share on other sites

StringMid: 

Retrieve x characters from the y position in the string. 

I don´t know how much letters the name has.

Same for StringLeft retrieve x characters from the left of the string

 I know there is a " " space on the left side of the firstname: " "john

and a "@" on the right side of the lastname: smith"@"

Edited by hendrikhe
Link to comment
Share on other sites

$firstNameEnd = StringInStr($email[0], ".")             ; Gets the length of the first name + the period
$firstName = StringMid($email[0], 1, $firstNameEnd - 1) ; Get the name up until the period but not including the period (-1)
$email[0] = StringTrimLeft($email[0], $firstNameEnd)    ; Remove the first name and period from the email string

Same concept for the last name. If you wanted to just have the first and last name in one variable and not have to worry about getting the first and then the last then use StringReplace to replace the "." with a space " " and just do the StringInStr using the "@" (Replacing the "." with " " will format the string as John Smith@dotmail com)

Link to comment
Share on other sites

Or use StringSplit to split the string at "@":

$sString = "John.Smith@Company.com"
$aTemp = StringSplit($sString, "@")
$sName = StringReplace($aTemp[1], ".", " ")
MsgBox(0, "Name", $sName)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

$aTemp = StringSplit($sString, ".@")

Even better than my solution :thumbsup:

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Is it only me that always forgets StringSplit can do that?

As you can see you are not the only one :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Also, a regex way :

$email = " john.smith@dotmail.com"
$name = StringRegExpReplace($email, "([^.]+)\.([^@]+).*", "$1 $2")
; $name = Execute("'" & StringRegExpReplace($name, "\b(\w)", "' & StringUpper('$1') & '") & "'") ; proper case
MsgBox(0, "Name", $name )

 

Edited by jguinch
Link to comment
Share on other sites

I always forget RegExp - intentionally ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Just for fun.

Local $sString = "John.Smith@Company.com"
Local $aTemp[2] = [StringMid($sString,1,StringInStr($sString,".")-1),StringMid($sString,StringInStr($sString,".")+1,StringInStr($sString,"@")-StringInStr($sString,".")-1)]
MsgBox(0, "Name", $aTemp[0] & $aTemp[1])

Saludos

Link to comment
Share on other sites

hendrikhe,
as you can see there are many ways to skin this cat ;)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...