question

Saga-3468 avatar image
0 Votes"
Saga-3468 asked Saga-3468 answered

Raw number in string validation

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


dotnet-cli
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Saga-3468 avatar image
0 Votes"
Saga-3468 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.