So I have a string like this:
string sampleString = "this - is a string - with hyphens - in it";
The thing to note here is that there are a random number of spaces to the left and to the right of the hyphens. The goal is to replace space in my string WITH a hyphen (hence the problem with hypens in the string). So the result I'm after should look like this:
"this-is-a-string-with-hyphens-in-it".
Currently I'm using:
sampleString.Trim().ToLower().Replace(" ", "-")
but this results in the following output:
"this---is-a-string------with-hyphens--------in-it"
Looking for the cleanest, most concise solution to this.
Thanks!