Remove first and last characters from a string

string="|abcdefg|"
echo "${string:1:${#string}-2}"