List help please...

Hi there,

I’m trying to put together a script that takes a filename and returns the person’s name.

Here’s my script so far:-

set x to "XYZ-Bloggs_Fred-CS.pdf"

set charCount to length of x
set AppleScript's text item delimiters to ""

set pCount to 1
set part to {}

repeat with i from 1 to charCount
	
	set asciiVal to ASCII number of character i of x
	
	if asciiVal ≥ 65 and asciiVal ≤ 90 or asciiVal ≥ 97 and asciiVal ≤ 122 then
		
		display dialog "It's ok    " & character i of x & "  " & asciiVal
		
		set char to character i of x as text
		set part to part & char
		set pCount to pCount + 1
		
	else
		set pCount to pCount + 1
	end if
	
end repeat

display dialog part as text

This works in as far as it gives me just the letters of the filename.
What I’ve been trying to do, and haven’t succeeded yet, is split it down further so it gives me:-

XYZ
Bloggs
Fred
CS
pdf

I’ve tried a number of things like a list of lists etc but no luck yet. I know what I wanna do it’s just the doing it!

Please can someone help?

Thanks in advance,

Nick

Hi Nick,

one possible solution is this:

set Delim to {"-", "_", "."}
set x to "XYZ-Bloggs_Fred-CS.pdf"
set TID to text item delimiters
repeat with i in Delim
	set text item delimiters to i
	set x to text items of x
	set text item delimiters to space
	set x to x as text
end repeat
set text item delimiters to TID
set x to words of x

Hi Stefan,

Thanks for your post and solution to the query, it’s really neat.
I did wonder if there was some way I could set more than one text item delimiter, I know
that’s not quite whayou’ve done but it’s kinda close.

I’d gone the other way and looked at ASCII ranges to allow for any odd characters that may
come along. Only looking for lower case or upper case letters would ensure nothing else should
get through. My problem was getting the separate bits into some sort of list or array.

Thanks again for having a look at this for me. :slight_smile:

Regards,

Nick

EDIT: Hi Stefan, I had a play with your code last night and of course it works perfectly. Having put a couple of ‘display dialogs’ in I could see better what was happening. It’s a nice way of getting rid of unwanted characters. I’m pretty sure the method will come in useful in the future.

Thanks again Stefan.

Nick