Showing posts with label Converting. Show all posts
Showing posts with label Converting. Show all posts

Tuesday, July 28, 2009

Convert from string to byte

public static byte[] StringToByte(string InString)

{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

Byte[] bytes = encoding.GetBytes(InString);

return bytes;
}

Saturday, July 25, 2009

Convert Double from String

    public static double getDoublefromString(string svalue)
    {
        double i = 0.00;
        try
        {
            i = Double.TryParse(svalue, out i) ? i : 0.00;
        }
        catch
        {
        }
        return i;
    }

Convert Int from String

     public static int getIntfromString(string svalue)
    {
        int i = -1;
        try
        {
            i = int.TryParse(svalue, out i) ? i : -1;
        }
        catch
        {
        }
        return i;
    }