So I have a line like this:
string sampleString = "this - is a string - with hyphens - in it";
It should be noted that there is a random number of spaces to the left and right of the hyphen. The goal is to replace the space in my string with a hyphen (hence the problem with hypens in the string). So the result that I have to do should look like this:
"this-this-line-with-hyphen-in-it."
I am currently using:
sampleString.Trim().ToLower().Replace(" ", "-")
but this leads to the following result:
"this --- this is a string ------ with a hyphen -------- something"
Look for the cleanest, most concise solution for this.
Thank!
Scott source
share