Raw number in string validation

Saga 426 Reputation points
2021-04-08T14:56:19.193+00:00

Hi all!

I have a text data file with number fields in 7 character spaces. The rules are:

  1. Right justified
  2. Left "0" pad
  3. If negative, sign is immediately to the left of the most significant digit

For example, the number 126.55 is represented like the following:

0012655 -or its negative counterpart: 0-12655

Invalid examples of the above number:

-012655 1265500 12655 012655

I am having problems coming up with a reliable algorithm to test these conditions. Some, like 1265500 are impossible to test for right justification because it could be a valid representation of 12,655.00

I want to ask here to get orientation from people who have come across such a scenario. Any feedback is welcomed! Thank you for your time. Saga

I need to verify he

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
326 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Saga 426 Reputation points
    2021-04-09T02:12:21.607+00:00

    Update:

    For #1, right justified, I did not find a suitable solution to verify this.

    For the others, I parsed the 7 char numeric string to an integer, then took that integer and converted it back to a string, eft padding it with zeroes. If this was identical to the original string then it was left padded.

    As a bonus, this also verified tat the negative sign was immediately to the left of the most significant digit.

    Thanks to all that gave this a read. Saga

    0 comments No comments