Uppercase first char of string

How would I capitalize the first letter of a string without knowing what the first letter may be? With ‘sed’ I can use substitution to do this…

echo bob | sed s/b/B/
-->Bob
echo bob | sed s/b/B/g
-->BoB

But if I wanted use a variable, eg., $USER, I wouldn’t necessarily know what the first letter would be, example

display dialog "Hello " & (do shell script "echo $USER")
-->"Hello bob" (short usename all lowercase)

Would ‘tr’ work? This returns all uppercase

echo $USER | tr "[a-z]" "[A-Z]"
-->"BOB" (short usename all uppercase)

Is there a way to return “Hello Bob”?
I know that I can do this…

display dialog "Hello " & (do shell script "finger $USER | grep Login | colrm 1 46 | awk '{print$1}'")
-->"Hello Bob"

I’m just curious if I could use ‘tr’ or ‘sed’. I tried using variations of [A-Za-z] in the mix, but I keep getting errors.

I might try something like this but I don’t know if it is suitable for a distributed script. Text issues and languages other than English aren’t my strong points. :stuck_out_tongue:

set user_ to do shell script "echo $USER"
display dialog "Hello " & (ASCII character ((ASCII number of character 1 of user_) - 32)) ¬
	& text 2 thru end of user_

– Rob

This is code that I’ve recently written (G&R, one guess why I wrote it):

set the_string to "\"this is a string,\" he said."

set the_string_as_title to my convert_to_title_or_sentence_case(the_string, "title")
set the_string_as_sentence to my convert_to_title_or_sentence_case(the_string, "sentence")
return the_string_as_title & return & the_string_as_sentence

on convert_to_title_or_sentence_case(the_string, the_case)
	set return_string to characters of the_string
	repeat with i from 1 to (length of return_string)
		set the_num to ASCII number (item i of return_string)
		if the_num is greater than or equal to 97 and the_num is less than or equal to 122 then exit repeat
	end repeat
	set item i of return_string to (ASCII character (the_num - 32))
	if the_case = "title" then
		try
			repeat with j from (i + 1) to (length of return_string)
				if item j of return_string is not in (characters of "abcdefghijklmnopqrstuvwxyz") then
					set the_num to ASCII number (item (j + 1) of return_string)
					if the_num is greater than or equal to 97 and the_num is less than or equal to 122 then set item (j + 1) of return_string to (ASCII character (the_num - 32))
				end if
			end repeat
		end try
	end if
	return return_string as string
end convert_to_title_or_sentence_case