• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 594
  • 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("-")));

0
CoffeeAddict
Asked:
CoffeeAddict
1 Solution
 
jjardineCommented:
newOrder.Comment = newOrder.Comment.Replace(oldFileName.Substring(0,oldFileName.IndoexOf("-")),newFileName.Substring(0,newFileName.IndexOf("-")));
0
 
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

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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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