• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 659
  • Last Modified:

String.Replace not working

When I run this and after this line, I check the Comment by mousing over it in VS, but the strings are not replaced.  The strings in the params are definitely different so it should have replaced the strings and the Comment definitely has the string it's looking for.

newOrder.Comment.Replace(oldFileName.Substring(0, oldFileName.IndexOf("-")), newFileName.Substring(0, newFileName.IndexOf("-")));

1 Solution
newOrder.Comment = newOrder.Comment.Replace(oldFileName.Substring(0,oldFileName.IndoexOf("-")),newFileName.Substring(0,newFileName.IndexOf("-")));
Guy Hengel [angelIII / a3]Billing EngineerCommented:
that's normal, because the replace function returns the string with the replaces characters, it does not replace direclty in the variable
newOrder.Comment = newOrder.Comment.Replace(oldFileName.Substring(0, oldFileName.IndexOf("-")), newFileName.Substring(0, newFileName.IndexOf("-")));

Open in new window

that method returns a string -- it doesn't directly modify the string itself
newOrder.Comment = newOrder.Comment.Replace...
CoffeeAddictAuthor Commented:
Thank you for explaining.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now