Variable Javascript String Substring Function Java