Rivasa
Rivasa

Reputation: 6750

Replacing a " - " with a single space? Replace method not working

i was working on a personal program, and in it, i get some strings which may have a space hyphen space. or something like this: " - " and what I have to do is replace this with a single space. Now, the problem is, when i try to use a replace method from the c# library it doesn't seem to do anything. This is what i tried:

string firsttext = firsttextbox.Text.ToLower();
string name = firsttext.Replace(" - ", " ");

But this fails to replace the string in firsttext's space hyphen space pattern with a single space. So when i try to use this text for example:

Code Geass - Lelouch of the Rebellion

it just returns this into string name:

Code Geass - Lelouch of the Rebellion

however it should actually be returning this:

Code Geass Lelouch of the Rebellion

Whats wrong with my idea? Or can I do it differently? Thanks for the help in advance.

Full code for those requested: http://pastebin.com/hwUtFe8N

Upvotes: 1

Views: 3675

Answers (1)

abelenky
abelenky

Reputation: 64710

In your code, I only see .Replace(" ", "-");
(eg. Replace space with dash)

I don't see what you describe, which is replacing a space-dash-space with just a space.

In otherwords, your code doesn't match your question.

Upvotes: 6

Related Questions