top of page

14. Split Up a Name (simple)

Description

Parses a full name into its component names.

Code

Simple Parser

""
SET Pos-n TO POSITION( FullName-t, " " )
SET FirstName-t TO FIRST( FullName-t, Pos-n - 1 )
SET LastName-t TO LAST( FullName-t, LENGTH( FullName-t ) - Pos-n )
IF LastName-t CONTAINS( " " )
SET Pos-n TO POSITION( LastName-t, " " )
SET MiddleName-t TO FIRST( LastName-t, Pos-n - 1 )
SET LastName-t TO LAST( LastName-t, LENGTH( LastName-t ) - Pos-n )
END IF

Explanation

This computation requires a temporary number variable, Pos-n. (Set it to "Ask only in dialog", "Do not warn if unanswered", and "Do not save in answer file" in the Advanced options).

The first line (after "") tells the computation the position of the first space in the string. It presumes that this space marks the end of the first name.

The second line extracts everything from the beginning of the string up to the space and places it in a text variable, FirstName-t.

The third line extracts everything after the space and places it in a text variable, LastName-t.

The following block repeats the same procedure, this time analyzing LastName-t to see if it has a space in it. If so, it splits this name into MiddleName-t and LastName-t.

Limitation: This does not recognize prefixes or suffixes, and will not work with names longer than three elements.

©2023 by My Site. Proudly created with Wix.com

  • Facebook
  • Twitter
  • LinkedIn
bottom of page