How do I get the nth character from a string?

How to I get the nth character from a string in shell script. For instance, I have a string London. I want to get, say the first character (L) from the string. How do I do this in unix shell?

Thankx

To get d From London

echo "London" | head -c 4 | tail -c 1

You could also use the Bash specific construct. See this

$ echo $JAVA_HOME
/usr/java/j2sdk1.4.2_07
$ echo ${JAVA_HOME:0:1}
/
$ echo ${JAVA_HOME:1:1}
u

Or..

expr substr London 1 1

Ksh93 has some extra string things, like:

$ x=London
$ print ${x:3:1}          ;# syntax is ${string:index:length}
n

cheers

echo "London" | head -c 4 | tail -c 2