I borrowed some functions from the thread I posted above.
Try the following:
[tt]
CREATE dbf test (name c(30), fname c(10), mname c(10), lname c(10))
INSERT INTO test (name) VALUES ("Abucsai Sándorn")
INSERT INTO test (name) VALUES ("Acél Antónia")
INSERT INTO test (name) VALUES ("Abonyi Pál Tamá")
INSERT INTO test (name) VALUES ("Ácsné Vadász Ág")
SCAN
new_strg = TRIM(name)
* Reduce multiple spaces to a single space
DO WHILE at(' ',new_strg) > 0
new_strg = STRTRAN( new_strg,' ',' ')
ENDDO
* Count words
wcount = words(new_strg)
* Parse and replace
DO CASE
CASE wcount = 1
REPLACE fname WITH new_strg
CASE wcount = 2
REPLACE fname WITH wordnum(new_strg, 1)
REPLACE lname WITH wordnum(new_strg, 2)
CASE wcount = 3
REPLACE fname WITH wordnum(new_strg, 1)
REPLACE mname WITH wordnum(new_strg, 2)
REPLACE lname WITH wordnum(new_strg, 3)
ENDCASE
ENDSCAN
FUNCTION words
PARAMETER strg
PRIVATE strg
RETURN (OCCURS(" ", strg) + 1)
* Return word number "w_num" from string strg
FUNCTION wordnum
PARAMETERS strg, w_num
PRIVATE strg, w_num, ret_str
DO CASE
CASE w_num > 1
DO CASE
CASE AT(" ",strg,w_num-1) = 0 && No word w_num.
ret_str = ""
CASE AT(" ",strg,w_num) = 0 && w_num is last word.
ret_str = SUBSTR(strg, ;
AT(" ",strg,w_num-1)+1,255)
OTHERWISE && Word w_num is in the middle.
strt_pos = AT(" ",strg,w_num-1)
ret_str = SUBSTR(strg,strt_pos, ;
AT(" ",strg,w_num)+1 - strt_pos)
ENDCASE
CASE w_num = 1
IF AT(" ",strg) > 0 && Get first word.
ret_str = SUBSTR(strg,1,AT(" ",strg)-1)
ELSE && There is only one word.
ret_str = strg
ENDIF
ENDCASE
ret_str = ALLTRIM(ret_str)
RETURN ret_str[/tt]
Have a nice weekend.