I m having a string, I need to check if that string contains any number or not. I found so many answers which only returns true or false Like this. But what I want to do is identify that number and replace it with another string. For example,
let myString = "/example/123/anotherstring"
or
let myString = "/example/anotherstring/123"
String can be anything like above. Expected output is 123 should be replaced by any other string. like
let expectedString = "/example/replaced/anotherstring"
or
let expectedString = "/example/anotherstring/replaced"
I Know one way to solve this is, loop this string and find the position of number and then replace that. but I don't want to do that. Is there any better way to do this?
NOTE: The number can be anything, It's not static/known number. So this does not help me.
Any help would be appreciated.