Remove/ignore middle initial when one exists

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Remove/ignore middle initial when one exists

by zirjeo on Wed Nov 16, 2016 10:25 pm

WIndows 10, IE11, VERSION BUILD=11.5.498.2403

How would I go about removing a middle initial IF a middle initial exists? Most of the time its just first and lastname, but on occasion there's a middle initial. Trying to figure out how to deal with the exceptions.

If there was always a middle initial I know I could do something like this below, but if there isn't one I would get "undefined John". Also will notice below I'm looking to have it in the format Lastname Firstname.

Code: Select all
SET !VAR1 John<SP>S.<SP>Doe
SET !VAR2 EVAL("var s='{{!VAR1}}'; var x,y; y=s.split(' '); y[2] + ' ' + y[0];")
PROMPT "{{!VAR2}}"



Thanks
WIndows 10, IE11, VERSION BUILD=11.5.498.2403
zirjeo
 
Posts: 59
Joined: Thu Oct 27, 2016 6:49 pm

Re: Remove/ignore middle initial when one exists

by ngangoh on Thu Nov 17, 2016 4:27 am

zirjeo wrote:WIndows 10, IE11, VERSION BUILD=11.5.498.2403

How would I go about removing a middle initial IF a middle initial exists? Most of the time its just first and lastname, but on occasion there's a middle initial. Trying to figure out how to deal with the exceptions.

If there was always a middle initial I know I could do something like this below, but if there isn't one I would get "undefined John". Also will notice below I'm looking to have it in the format Lastname Firstname.

Code: Select all
SET !VAR1 John<SP>S.<SP>Doe
SET !VAR2 EVAL("var s='{{!VAR1}}'; var x,y; y=s.split(' '); y[2] + ' ' + y[0];")
PROMPT "{{!VAR2}}"



Thanks


try to change this part:
Code: Select all
SET !VAR2 EVAL("var s='{{!VAR1}}'; var x,y; y=s.split(' '); y[2] + ' ' + y[0];")

with this:
Code: Select all
SET !VAR2 EVAL("var s='{{!VAR1}}'; var x,y; y=s.split(' ');if(y.length==3){y[2] + ' ' + y[0]}else{y[1]+' ' + y[0]};")
ngangoh
 
Posts: 2
Joined: Sat Nov 05, 2016 11:37 am

Re: Remove/ignore middle initial when one exists

by zirjeo on Thu Nov 17, 2016 9:36 am

Did not know you could do if else statements in eval, this is going to help me a lot. Thank you!
WIndows 10, IE11, VERSION BUILD=11.5.498.2403
zirjeo
 
Posts: 59
Joined: Thu Oct 27, 2016 6:49 pm


Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: No registered users and 2 guests

-->