I have a string and I want to replace every space in this string with a + I tired this by using:
tw.Text = strings.Replace(tw.Text, " ", "+", 1)
But that didn't worked for me...any solutions?
For example the string could look like:
The answer of the universe is 42
Approach: Count the total spaces in a string in one iteration, say the count is spaceCount. Calculate the new length of a string by newLength = length + 2*spaceCount; (we need two more places for each space since %20 has 3 characters, one character will occupy the blank space and for rest two we need extra space)
Use the replace() method to remove all whitespace from a string in TypeScript, e.g. str. replace(/\s/g, '') .
The easiest approach to remove all spaces from a string is to use the Python string replace() method. The replace() method replaces the occurrences of the substring passed as first argument (in this case the space ” “) with the second argument (in this case an empty character “”).
Use strings.ReplaceAll
tw.Text = strings.ReplaceAll(tw.Text, " ", "+")
If you're using an older version of go (< 1.12), use strings.Replace
with -1
as limit (infinite)
tw.Text = strings.Replace(tw.Text, " ", "+", -1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With