I know that there are already solution descriptions, but they don’t help me.
I have a DT with three columns. The middle “material” is a string, the other two are an INT.
I have to compare the “material” afterwards with another table where I only have INT everywhere.
The “material” number has a maximum of 7 digits. In the string, this is filled with zeros at the beginning (e.g. 0012345). Now I can’t compare that to the other table because it says 12345.
comparing seven correct diggits works beautifully (e.g. 7654321). I only have problems with the zeros.
What do I have to do so that I can convert the “Material” column in a DT like this.
For each row? but with which Assigne command?
Please describe the command in detail so that I understand it too
Thanks in advance !
While you convert string numbers prefix with 0 to integer, 0 will vanish.
For string, you can use the @TUSHAR_DIWASE solution. If you try to convert it to an integer, again 0 will vanish. Because 0 has no value when it is in a prefix.
So kindly change your Comparing method. Can you tell us how do you need to compare your values? What’s the condition? Provide us with some examples. It may use us to provide better solutions for you.
HI ,
VariableToCompare is a new string varible which hold material value coming from excel.
VariableToCompare is 7 digit string. so you can compare with other other table value.
As @Gokul_Jayakumar mentioned , if you convert this VariableToCompare into int type then again it lose its leading zero.
so you can use if condition
VariableToCompare.trim.contains(OthertableCellValue.tostring.trim)
with 777777 and 1111111 it works wonderfully. BUT not when I compare 0012345 and 12345 or 0654321 with 654321.
What’s important is that I don’t need this “0” at the beginning! Those must be removed
but be careful, there can also be a “0” somewhere in the middle or at the end. Of course it has to stay.
is it better to understand now?
In the Linq Query, You could try converting both the values x("Material").ToString and d("Material").ToString to Double or Integer for same type comparison like below :
Hello, I have another ideea.
I can figure out the x function gets the number and d gives a String.
You can change the condition, which compares the values, like this:
You can use TrimStart() as Adrian mentioned but use it on x(“Material”) instead. d(“Material”) is from the basic table which doesn’t have any leading zeros.
(From d In dt_Basic.AsEnumerable
Where Not dt_workfile.AsEnumerable.Any(Function (x) x("Material").ToString.TrimStart("0"c).Equals(d("Material").ToString.Trim))
Select d).toList