Sign in to follow this  
Followers 0
Medic873

Pull First And Last name

7 posts in this topic

Okay I alwys have trouble doing things like this.

I am trying to pull the first name under the variable $FirstName

And the second name under the variable $Lastname

This url always just loads a new name so I always have random names

http://www.behindthename.com/random/random.php?number=2&gender=m&surname=&all=yes

But I cant seem to accuratly pull them pleaes help thank you

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$_NameArray = StringSplit ( 'Eadwig kresimir", ' ' ) ; use a space as delimiter
$FirstName = $_NameArray[1]
$Lastname =$_NameArray[2]

That's good for you ? Posted Image

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

I was looking to copy somthing like this

$vLoremText = _StringBetween(_INetGetSource('http://lipsum.com/feed/html'), '<div id="lipsum">', '</div>')

MsgBox(0, "", StringReplace(StringReplace($vLoremText[0], '</p>', ''), '<p>', ''))

but I dont really understand how to

Share this post


Link to post
Share on other sites

can anyone help me with this

Share this post


Link to post
Share on other sites

From the website you listed, this works for me:

#include <string.au3>
#include <INet.au3>

$Source = _INetGetSource('http://www.behindthename.com/random/random.php?number=2&gender=m&surname=&all=yes')
$Name = _StringBetween($Source, '<a href="/name/', '</a> </font></center><br><br><br>')
If @error Then Exit
$FullName = _StringProper(StringRegExpReplace($Name[0], '" class="plain">.*</a>  <a href="/name/.*" class="plain">', ' '))
Msgbox(32, 'Extracted Name', $FullName)

Share this post


Link to post
Share on other sites

OMG it works thank you so much I was trying so many diffrent things im going analyze how you did it and see If I cant figure it out for my self and future reference.

Although If you could help me how can I now divide the variable $FullName into two variable

I image the best way to do this is by saying anything in front of the first space = $Firstname

Anything after space is $Lastname How do I do this I can only find things to divide a string by its length not spaces.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You can use StringSplit or _StringBetween or even StringRegExpReplace...here is an example with _StringBetween

#include <string.au3>
#include <INet.au3>

$Source = _INetGetSource('http://www.behindthename.com/random/random.php?number=2&gender=m&surname=&all=yes')
$Name = _StringBetween($Source, '<a href="/name/', '</a> </font></center><br><br><br>')
If @error Then Exit
$FullName = _StringProper(StringRegExpReplace($Name[0], '" class="plain">.*</a>  <a href="/name/.*" class="plain">', ' '))
$Firstname = _StringBetween($FullName, '', ' ')
$Lastname = _StringBetween($FullName, ' ', '')
Msgbox(32, 'Extracted Name', 'Full Name = ' & $FullName & @LF & 'First Name = ' & $Firstname[0] & @LF & 'Last Name = ' & $Lastname[0])

Let me know if you need me to add comments to explain what is going on in the script

Edited by Varian

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
Sign in to follow this  
Followers 0