Lowercase and Uppercase...

I have a script:

set caps to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
set letters to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
set meow to 0
set letter to {}
repeat count letters times
	set meow to meow + 1
	set letter to letter & {{lowercase:(item meow of letters), uppercase:(item meow of caps)}}
end repeat
return lowercase of item 7 of letter

The problem I have is that I want to be able to say

return lowercase of g of letter

instead of

return lowercase of item 7 of letter

Can someone help?

Hi,

in alphabetical order you can use the id (ASCII number) of the letter


return lowercase of item ((id of "g") - 96) of letter

OK… Here’s an example of my script:

set caps to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
set letters to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
set meow to 0
set letter to {}
repeat count letters times
	set meow to meow + 1
	set letter to letter & {{lowercase:(item meow of letters), uppercase:(item meow of caps)}}
end repeat
set hello to (choose from list caps with prompt "What letter?") as string
set hello to lowercase of item ((id of hello) - 64) of letter
display dialog hello & " is " & (id of hello) - 96

easier without repeat loop


set caps to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
set hello to (choose from list caps with prompt "What letter?") as text
if hello is "false" then return
set hello to do shell script "/bin/echo  " & hello & " | /usr/bin/tr A-Z a-z"
display dialog hello & " is " & (id of hello) - 96

Here a nice Handler for Upper- and Lowercase:

-- set a to my toUpperLowercase("yourString", true) -- true = upper, false = lower
on toUpperLowercase(theString, CaseVar)
	set retstring to ""
	repeat with i from 1 to count character of theString
		set tmpChar to ASCII number of character i of theString
		if CaseVar = true then
			if tmpChar ≥ 97 and tmpChar ≤ 122 then set tmpChar to tmpChar - 32
		else
			if tmpChar ≥ 65 and tmpChar ≤ 90 then set tmpChar to tmpChar + 32
		end if
		set retstring to retstring & (ASCII character tmpChar)
	end repeat
	return retstring
end toUpperLowercase

Greets from
TMA

The Satimage OSAX too has ‘uppercase’ and ‘lowercase’ functions:

uppercase "hello" --> "HELLO"
lowercase "HELLO" --> "hello"

. and a ‘change’ function which might be usable for capitalising initials, but I haven’t looked into it.

Presumably, the solutions in this thread make the orignal enquiry redundant. But, as posed, it would require a record of records rather than a list of them. This would have to be either written out in longhand or constructed so:

set caps to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
set letters to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}

set letter to "{"
repeat with meow from 1 to (count letters)
	set letter to letter & (item meow of letters) & ":{|lowercase|:\"" & (item meow of letters) & "\", |uppercase|:\"" & (item meow of caps) & "\"},"
end repeat
set letter to (run script (text 1 thru -2 of letter) & "}")
--> {a:{|lowercase|:"a", |uppercase|:"A"}, b:{|lowercase|:"b", |uppercase|:"B"}, c:{|lowercase|:"c", |uppercase|:"C"}, d:{|lowercase|:"d", |uppercase|:"D"}, e:{|lowercase|:"e", |uppercase|:"E"}, f:{|lowercase|:"f", |uppercase|:"F"}, g:{|lowercase|:"g", |uppercase|:"G"}, h:{|lowercase|:"h", |uppercase|:"H"}, i:{|lowercase|:"i", |uppercase|:"I"}, j:{|lowercase|:"j", |uppercase|:"J"}, k:{|lowercase|:"k", |uppercase|:"K"}, l:{|lowercase|:"l", |uppercase|:"L"}, m:{|lowercase|:"m", |uppercase|:"M"}, n:{|lowercase|:"n", |uppercase|:"N"}, o:{|lowercase|:"o", |uppercase|:"O"}, p:{|lowercase|:"p", |uppercase|:"P"}, q:{|lowercase|:"q", |uppercase|:"Q"}, r:{|lowercase|:"r", |uppercase|:"R"}, s:{|lowercase|:"s", |uppercase|:"S"}, t:{|lowercase|:"t", |uppercase|:"T"}, u:{|lowercase|:"u", |uppercase|:"U"}, v:{|lowercase|:"v", |uppercase|:"V"}, w:{|lowercase|:"w", |uppercase|:"W"}, x:{|lowercase|:"x", |uppercase|:"X"}, y:{|lowercase|:"y", |uppercase|:"Y"}, z:{|lowercase|:"z", |uppercase|:"Z"}}

return |lowercase| of g of letter
--> "g"

I’ve used bars in the ‘|uppercase|’ and ‘|lowercase|’ labels because I have the Satimage OSAX installed. If you don’t have it installed, the bars won’t appear in the ‘return’ line when you compile the script or in the constructed record when you run it.