Yahoo Answers is shutting down on 4 May 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Which is more efficient? String.Format() or String.Replace()?

i want to replace a number of chars in a string in C#.NET

the obvious choice is of cource String.Replace() but i was told that maybe passing two Zeos to String.Format() can do basically the same thing. so i was woundering which of the two is more efficient/Fast?

thanks.

3 Answers

Relevance
  • 1 decade ago
    Favourite answer

    My guess is that format is faster because you basically supply the template for it to use and it puts what you have into it. Replace has to search for the characters throughout the string.

    However I doubt you would ever see a noticeable difference in the two.

    The only prob with format is that you do have to validate the string prior to running to make sure it will fit in the format you desire.

  • 1 decade ago

    I agree with the previous answer in that the performance difference would probably be un-noticeable. We tend to forget how fast functions that are working on data that's entirely in memory actually execute.

    A good reason to go with Replace over Format would be clarity. If I am reading your code and I see Replace it's immediately obvious to be that you are replacing character, but if I see Format it may take me a little time to realize you are using it to do a replace.

  • ?
    Lv 4
    5 years ago

    Water by utilising some distance. sunlight is robust merely for sparkling days, and for merely 6-8 hrs on the main. Plus it rather is merely too costly to purchase the photograph voltaic panels for electrical energy. below glass tubing is low priced yet nevertheless too short an afternoon easy time source. Wind is greater low priced routinely, and in all probability greater hours of production standard. yet nevertheless relies upon on adequate air circulation. Water from river flow is the main consistent 24/7 production. Dams, are costly yet are multipurpose. electrical energy, irrigation, eating, game, flood administration. Paddle wheels anchored alongside rivers or streams additionally produce non-end electrical energy and are low priced. they could be smaller or larger. Ocean waves and tides are being appeared at as a non-end source additionally. All water supplies of renewable capability are by utilising some distance and away the foremost. Water is heavy at 8+ lbs according to gal. it does not take very lots flow on a lever arm to multiply its result dramatically.

Still have questions? Get answers by asking now.