C# Converting string to long

Hello.

I am trying to convert a string to a long. I am able to convert the string to a long. But my string begins with a bunch of zeros (14 to be exact, bringing the total length of the string to 16). Whenever I parse it, it only keeps the last two numbers and drops all the zeros. I need it to keep the original string, and not get rid of anything in the string, keeping it’s length to 16.

The string changes very often, since it represents the id of a player, so it changes based on which player is playing. So one string could possibly contain 13 instead of the 14 mentioned above. So I would need it to work with that as well.

Is there a way to do this? Like a line of code to convert all 16 characters in the string to a long?

So far I have this:

long myLong = long.Parse(myString);

Any help is greatly appreciated.

To convert a long back into a string, you can pad it with zeros using (for some long variable l):

l.ToString("D16");

This tells it to convert the long to a decimal representation with 16 digits. The following example takes the string, converts it to a long, and then regenerates the string with the padding.

string str = "0000000000000013";
long l = long.Parse(str);
str = l.ToString("D16");

Is this what you were looking for?