Complexity is O (m + n), where m is the size of the input and n is the size of the output file.
If you do not pass additional parameters, for example, in your case, the time complexity is O (2 * m) = O (m).
But keep in mind that your code may fail because s may contain the formatting codes themselves, and this will result in the result undefined / unknown / unpredictable / possible_very_bad, as indicated by Adriano.
source share