Jump to content
hendrikhe

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

Recommended Posts

hendrikhe

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

Share this post


Link to post
Share on other sites
hendrikhe

yes always the same . like marta.cruz@touchmail.com

 

firstname"."lastname"@"email.com

Edited by hendrikhe

Share this post


Link to post
Share on other sites
InunoTaishou

StringInStr (Find the period in the string, Find the @ in the string)

StringLeft or StringMid (Get the First name up until the period, Get the last name up until the @)

StringTrimLeft(Remove the first name from the string)

Share this post


Link to post
Share on other sites
hendrikhe

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

Share this post


Link to post
Share on other sites
InunoTaishou
$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)

Share this post


Link to post
Share on other sites
hendrikhe

hmm, yeah I got it. Very nice ideia.

 

I will try tomorrow, sounds like a very good solution!

 

Thank you very much

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water
$aTemp = StringSplit($sString, ".@")

Even better than my solution :thumbsup:

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

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

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

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
jguinch

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

Share this post


Link to post
Share on other sites
water

I always forget RegExp - intentionally ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Danyfirex

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

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
mikell
#include <String.au3>

$s = "marta.cruz@touchmail.com"
;$res = Execute("'" & StringRegExpReplace($s, "(\w)(\w+)\.(\w)(\w+)@.*", "' & StringUpper('$1') & '$2 ' & StringUpper('$3') & '$4' & '") & "'")
$res = _StringTitleCase(StringRegExpReplace($s, '(\w+).(\w+).*', "$1 $2"))
Msgbox(0,"", $res)

:D

Edited by mikell

Share this post


Link to post
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

×