bchavez / Bogus

:card_index: A simple fake data generator for C#, F#, and VB.NET. Based on and ported from the famed faker.js.
Other
8.62k stars 491 forks source link

Method to return numbers only string with a specific length... #461

Closed nirzaf closed 7 months ago

nirzaf commented 1 year ago

Method to return a numbers-only string with a specific length defined via parameter

ChristoWolf commented 10 months ago

Hi @nirzaf!

This is easily achievable using any of the Replace methods, so this proposal would unnecessarily bloat the API IMO.

Is there anything that you are missing from the current API?

bchavez commented 7 months ago

Hi. Thank you for the feedback. I think @ChristoWolf is right on this one for the moment. You'll need to create a custom extension method for this if you want better API ergonomics. If there's enough demand for this new method to be in the Bogus API, then we'll consider it in the future; but for now, your best advice is to create a custom extension method; or use the Random.Replace*() methods as shown below:

void Main()
{
   var f = new Faker();

   f.Random.ReplaceNumbers(new string('#', 25)).Dump();
   f.Random.NumberOnlyString(25).Dump();;
}

public static class MyCustomExtensions
{
   public static string NumberOnlyString(this Randomizer r, int length)
   {
      return r.ReplaceNumbers(new string('#', length));
   }
}
//OUTPUT:
9618188693116119676746702
3035736940236164577423885