I have a string I extract New/Old info from. Looks like this below.
009CMNDSEQ665423412004OLDOFF IBA1004NEWOFF IS4S001PRO
Based on the Int before OLD/NEW, I strip the spaces, indexOf and fetch the Int number of chars 6 places after either OLD/NEW.
I fetch NEW first and in this example it incorrectly picks up S4S0, then it fetches OLD and correctly picks up IBA1.
NumOfChar is always correct for both. Why and how is IndexOf incorrectly counting the first # of chars ??
Code used
NumOfChar
in_TransactionItem.SpecificContent(“CommandData”).ToString.Substring(in_TransactionItem.SpecificContent(“CommandData”).ToString.IndexOf(“NEW”)-1, 1)
I should have expanded on my initial message. This code was tested and working 27Nov. When pushing to live 27Jan, it’s incorrectly picking the NEWOFF. The strings I’m looking for are NEWOFF and OLDOFF, hence the +6. I wrote it like that so I could use the same for NEWTTC and OLDTTC etc.
If I have a command sting that only contains NEWOFF and I use the first 2 items in my image, then it works perfectly. The minute it also has to go find OLDOFF in the same block, it fails the count.
So thanks for the replies.
Supriya - with a slight change to the numbers to include OFF, the result was still incorrect.
Parvathy - with that change to the index count, NEWOFF works, but OLDOFF fails.
Piotr - this is useful as a workaround, I did something similar in doing more assigns in a test, my problem then is I have to then add to and update 11 switches. I’m still stumped as to why it works if it’s only run with looking for NEWOFF, but breaks while looking for both.
It is because of the Spaces the error happens, the OLDOFF Replace Empty String removes only one space, where as the NEWOFF replaces two spaces and then computes the Substring, which gives it incorrect value.
The above simply handles this By first Capturing the data from the NEWOFF and OLDOFF, then replacing spaces with empty string, making sure that whatever spaces after it is removed and then Performing the required Substring with Num of Character extracted.
We are not sure of the data present then, maybe the data did not have spaces ?