String.Replace not working

Posted on 2008-11-18
Last Modified: 2012-05-05
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("-")));

Question by:CoffeeAddict
    LVL 14

    Accepted Solution

    newOrder.Comment = newOrder.Comment.Replace(oldFileName.Substring(0,oldFileName.IndoexOf("-")),newFileName.Substring(0,newFileName.IndexOf("-")));
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    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

    LVL 22

    Expert Comment

    that method returns a string -- it doesn't directly modify the string itself
    newOrder.Comment = newOrder.Comment.Replace...

    Author Comment

    Thank you for explaining.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now