This worked for me by calculating size of string.
It is easy you need to echo the value you need to return and then store it like below
removechars(){
var="some string.rtf"
size=${#var}
echo ${var:0:size-4}
}
removechars
var2=$?
some string