We have a requirement to transform a string containing a date in dd/mm/yyyy
format to ddmmyyyy
format (In case you want to know why I am storing dates in a string, my software processes bulk transactions files, which is a line based textual file format used by a bank).
And I am currently doing this:
string oldFormat = "01/01/2014";
string newFormat = oldFormat.Replace("/", "");
Sure enough, this converts "01/01/2014"
to "01012014"
. But my question is, does the replace happen in one step, or does it create an intermediate string (e.g.: "0101/2014"
or "01/012014"
)?
Here's the reason why I am asking this:
I am processing transaction files ranging in size from few kilobytes to hundreds of megabytes. So far I have not had a performance/memory problem, because I am still testing with very small files. But when it comes to megabytes I am not sure if I will have problems with these additional strings. I suspect that would be the case because string
s are immutable. With millions of records this additional memory consumption will build up considerably.
I am already using StringBuilder
s for output file creation. And I also know that the discarded strings will be garbage collected (at some point before the end of the time). I was wondering if there is a better, more efficient way of replacing all occurrences of a specific character/substring in a string, that does not additionally create an string.