# Problems with converting a DT from String to Int

Hi,

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

HI ,
you can try this

or

VariableToCompare=CInt(MaterialVariable).ToString(“0000000”)

1 Like

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.

I thought so too, so what should I do?

what do I have to do if this “VariableToCompare” is in a DT?

sorry i’m a beginner…

Why do you need to convert String to Integer @juergenh1975

Kindly give more details on what should you need to compare.

Did you need to check the number presents on other tables? In string it’s possible to check the data with other tables

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)

Hello, please try the next expression:

Either I explain it wrong or you don’t understand me. I make an example:

I have a “workfile” table:

WHN Material Qty
AA01 0012345 5
AA01 0654321 3
AA01 7777777 10
AA01 1111111 8

and I have a “Basic” table that I can’t modify:

Material
12345
654321
7777777
1111111

I don’t want to change the basic table !
then I have a formula where I compare and sort out material.

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 :

``````CDbl(x("Material").ToString.Trim) = CDbl(d("Material").ToString.Trim)
``````

Let us know if this does not help and what was the output produced.

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:

x(“Material”).toString.Trim.Equals(d(“Material”).TrimStart(Chr(Asc(“0”))))

``````(From d In dt_Basic.AsEnumerable