Search code examples
c#stringreplacescramble

Best way to replace string with random values exact length c#


I'm looking to replace a string with random values - and keep the same length. However, I'd like all characters to be replaced with chars, digits to be replaced with digits.

I'm wondering the best way to do this. I'm considering a for loop through each character but that could be potentially quite performance intensive.

I may be wrong, in which case please do let me know.

Thanks


Solution

  • You are wrong. To know whether it is a character or a digit, you need to look at each value in the string, so you need to loop over the string in any case.