-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?

4
  • 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. Commented Apr 6, 2020 at 20:58
  • 2
    String.Insert... Commented Apr 6, 2020 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. Commented Apr 6, 2020 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 stackoverflow.com/questions/3470990/… and softwareengineering.stackexchange.com/questions/80084/…. Commented Apr 7, 2020 at 12:42

1 Answer 1

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.