hendrikhe Posted January 11, 2016 Share Posted January 11, 2016 (edited) 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 Best regardsHendrik Edited January 11, 2016 by hendrikhe Link to comment Share on other sites More sharing options...
JohnOne Posted January 11, 2016 Share Posted January 11, 2016 And what if it's john-smith@dotmail.com or john_smith@dotmail.com or johnskith@dotmail.com or something else?Is it absolutely and always a "." separating names? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
hendrikhe Posted January 11, 2016 Author Share Posted January 11, 2016 (edited) yes always the same . like marta.cruz@touchmail.com firstname"."lastname"@"email.com Edited January 11, 2016 by hendrikhe Link to comment Share on other sites More sharing options...
InunoTaishou Posted January 11, 2016 Share Posted January 11, 2016 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) Link to comment Share on other sites More sharing options...
hendrikhe Posted January 11, 2016 Author Share Posted January 11, 2016 (edited) 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: " "johnand a "@" on the right side of the lastname: smith"@" Edited January 11, 2016 by hendrikhe Link to comment Share on other sites More sharing options...
InunoTaishou Posted January 11, 2016 Share Posted January 11, 2016 $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 stringSame 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 More sharing options...
hendrikhe Posted January 11, 2016 Author Share Posted January 11, 2016 hmm, yeah I got it. Very nice ideia. I will try tomorrow, sounds like a very good solution! Thank you very much Link to comment Share on other sites More sharing options...
water Posted January 11, 2016 Share Posted January 11, 2016 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Exit Posted January 11, 2016 Share Posted January 11, 2016 $sString = "John.Smith@Company.com" $aTemp = StringSplit($sString, ".@") MsgBox(0, "Name", $aTemp[1]&$aTemp[2]) JohnOne and water 2 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
JohnOne Posted January 11, 2016 Share Posted January 11, 2016 Nice.Is it only me that always forgets StringSplit can do that? jguinch and Exit 2 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
water Posted January 11, 2016 Share Posted January 11, 2016 $aTemp = StringSplit($sString, ".@")Even better than my solution Exit 1 My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted January 11, 2016 Share Posted January 11, 2016 Is it only me that always forgets StringSplit can do that?As you can see you are not the only one JohnOne 1 My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
jguinch Posted January 11, 2016 Share Posted January 11, 2016 (edited) 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 January 11, 2016 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
water Posted January 11, 2016 Share Posted January 11, 2016 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Danyfirex Posted January 11, 2016 Share Posted January 11, 2016 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 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
water Posted January 11, 2016 Share Posted January 11, 2016 (edited) hendrikhe,as you can see there are many ways to skin this cat Edited January 11, 2016 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
JohnOne Posted January 11, 2016 Share Posted January 11, 2016 As you can see you are not the only one It's even worse when it's the actual default behaviour. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jguinch Posted January 11, 2016 Share Posted January 11, 2016 $email = " john.smith@dotmail.com" $username = StringReplace (StringTrimRight($email, StringInStr($email, "@")), ".", " ") ConsoleWrite($username) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted January 11, 2016 Share Posted January 11, 2016 (edited) #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) Edited January 11, 2016 by mikell Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now