views:

150

answers:

3
+7  A: 

Strings are immutable, so the Replace function doesn't modify the string it is called on. You need to assign it again like you did in your second example.

And as other people have pointed out, the ToUpper call will ensure that variable names don't match.

Ray
+2  A: 

You've got a call to .ToUpper() in your second example. Is this what's causing the behaviour you see?

Greg Hewgill
+2  A: 

If I understand this correctly: Your first statement is not assigning the return value, since replace returns a new instance of the string replaced.

_body = _body.Replace("##" + _variableName + "##",
    templateVariables[_variableName]);

should fix you there.

The second instance you have the variable getting replace changed ToUpper() and the actual string containing mixed cased values.

Your string should be

Hello ##FIRSTNAME## ##LASTNAME##,
Pat
Thank you, everything looks the same after you stare it for hours.