-2

Our API is receiving VAT numbers as a 'string' data value without symbols. e.g. 'BE0123123123' and should be "transformed" into a structured field: 'BE 0123.123.123' input length will always be the same length and type.

Any suggestions on what would be the best approach?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Gregory
  • 149
  • 2
  • 5
  • 13
  • 1
    What have you tried? Surely you've at least attempted to add spaces and decimals yourself? That should be pretty darn trivial if the input is always the same format. – Broots Waymb Apr 06 '20 at 20:58
  • 2
    [String.Insert](https://learn.microsoft.com/en-us/dotnet/api/system.string.insert?view=netframework-4.8)... – Code Stranger Apr 06 '20 at 21:00
  • @BrootsWaymb Hi, I know there are many ways in doing this. But since this is a high performing API, and the speed is very important, i'm asking for some advice here. – Gregory Apr 06 '20 at 21:14
  • 1
    Have you benchmarked something like that too see how expensive of an operation it is? Unless you determine that it's a bottleneck, you shouldn't yet worry about making these sort of micro-optimizations. See https://stackoverflow.com/questions/3470990/is-micro-optimization-worth-the-time and https://softwareengineering.stackexchange.com/questions/80084/is-premature-optimization-really-the-root-of-all-evil. – Broots Waymb Apr 07 '20 at 12:42

1 Answers1

1

There are many solutions, one of them can be regex

Regex.Replace(input, @"(\w{2})(\w{4})(\w{3})(\w{3})", @"$1 $2.$3.$4");
user2316116
  • 6,726
  • 1
  • 21
  • 35