How can i do String manipulation using condition?