I assume you mean, how to calculate the moles in a substance from grams.
Firstly, you will need to take into account the mass number of the atoms in the molecular compound.
Say, H2O.
Hydrogen mass = 1.00794
Oxygen mass = 15.9994
I will then have to multiply the atoms by their quantities and combine the molecular compound atoms' mass, respectively.
(2)(1.00794) + (1)(15.9994) = 18.01528.
This is used as the divisor that is divided to grams, to find the moles of a substance.
For example, 10 grams is 10/18.01528 = 0.56 moles