Remove/ignore middle initial when one exists

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
zirjeo
Posts: 82
Joined: Fri Oct 28, 2016 1:49 am

Remove/ignore middle initial when one exists

Post by zirjeo » Thu Nov 17, 2016 5:25 am

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
ngangoh
Posts: 2
Joined: Sat Nov 05, 2016 6:37 pm

Re: Remove/ignore middle initial when one exists

Post by ngangoh » Thu Nov 17, 2016 11: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]};")
zirjeo
Posts: 82
Joined: Fri Oct 28, 2016 1:49 am

Re: Remove/ignore middle initial when one exists

Post by zirjeo » Thu Nov 17, 2016 4:36 pm

Did not know you could do if else statements in eval, this is going to help me a lot. Thank you!
Post Reply