sampleString = "Lorem ipsumxolor sit"
I want the immediate left and right characters of x
to be blank. The desired output would be "Lorem ipsu x lor sit"
Using stringtext = replace(stringtext, "x", " x ")
, the output is Lorem ipsum x olor sit
. However, the length of the string obviously increases and doesn't match the desired output.
Another limitation is that incase of sampleString = "Lorem ipsumxxxolor sit"
. I can't use stringtext = replace(stringtext, "x", " x ")
as the output becomes Lorem ipsum x x x olor sit
instead of the desired result Lorem ipsu xxx lor sit
. I can use replace(stringtext, "xxx", " xxx ")
but that would cause me to use multiple conditions instead of one single solution.
Is there an efficient way to deal with this?
Thank you!