-1

I have read all similar questions and acted accordingly. But still can't figure out what's wrong with my code.

This is my code, super simple. (I know this isn't valid XML. It's just for the example).

string replacement = "TimeSheetsReplaced";
string word = "TimeSheets";
string result = "<?xml version=\"1.0\" encoding=\"utf-16\"?><DisplayName>Timesheets</DisplayName>"; 
result = result.Replace("<DisplayName>" + word + "</DisplayName>", "<DisplayName>" + replacement + "</DisplayName>");

The result string remains unplaced. What am I doing wrong??

4
  • Why not just parse the XML using the classes in System.XML, modify the value properly and write it back out again? Commented Apr 9, 2013 at 8:55
  • time sheets has a capital s in word and not in result, but @PhonicUK's suggestion is correct way to do this.. Commented Apr 9, 2013 at 8:55
  • 1
    Case sensitivity in strings... Commented Apr 9, 2013 at 8:56
  • 1
    stackoverflow.com/a/6276004/284240 Commented Apr 9, 2013 at 8:56

3 Answers 3

3

TimeSheets != Timesheets

Casing does not match

Sign up to request clarification or add additional context in comments.

1 Comment

awesome! we answered in the exact same second :-)
1

It's because your string contains Timesheets, but you're lokoing for TimeSheets (with a capital S).

Comments

0

In your word TimeSheets has big S, in string small s

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.