used encoding safe substr