With a line modified as : “Test (1 (615)”, peavine’s proposal would return :
{1773, 1600, 10062, 898, 925, 78, 500, 400, 471, 1, 463, 39, 522, 423, 351, 9, 98, 127, 8, 12, 228, 111, 112}
Here is a modified version:
set theString to "Test 10 (1773)
Test 8 (1600)
Gò Vấp (10062)
Phú Nhuận (898)
Tân Bình (925)
Bình Chánh (78)
Bình Tân (500)
Bình Thạnh (400)
Test 9 (471)
Test (1 (615)
Test 12 (463)
Test 3 (39)
Tân Phú (522)
Thủ Đức (423)
Test 7 (351)
Cần Giờ (9)
Hóc Môn (98)
Test 2 (127)
Test 4 (8)
Test 5 (12)
Test 6 (228)
Test 11 (111)
Củ Chi (112)"
set theString to paragraphs of theString
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"(", ")"}
set numberList to {}
repeat with anItem in theString
if (count (get text items of anItem)) = 3 then
set end of numberList to (text item 2 of anItem) as integer
else
set end of numberList to anItem as text
end if
end repeat
set AppleScript's text item delimiters to astid
numberList
--> {1773, 1600, 10062, 898, 925, 78, 500, 400, 471, "Test (1 (615)", 463, 39, 522, 423, 351, 9, 98, 127, 8, 12, 228, 111, 112}
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 8 juillet 2020 18:01:44