Results 1 to 4 of 4

Thread: How to convert string to int

  1. #1
    Join Date
    Jun 2009
    Posts
    361

    How to convert string to int

    I have string s="somecomments" which i need to convert to its integer equivalent. Is it possible ?

    Can anyone tell me how to convert an int to a string value that I define? Please help.

  2. #2
    Join Date
    Feb 2009
    Posts
    673

    Re: How to convert string to int

    TO covert string to Int32, take this function:

    public static int ParseInt(object o, int defaultValue)
    {
    if (o == null || o == DBNull.Value)
    {
    return defaultValue;
    }
    try
    {
    return Int32.Parse(o.ToString(), CultureInfo.InvariantCulture);
    }
    catch (Exception ex)
    {
    if (!(ex is FormatException) && !(ex is InvalidCastException) && !(ex
    is OverflowException))
    {
    throw;
    }
    return defaultValue;
    }
    }

  3. #3
    Join Date
    Feb 2009
    Posts
    161

    Re: How to convert string to int

    you can make a function some like this to convert string to int:-


    <%

    ' CInt Converts to Integer
    ' CStr Converts to String
    ' TypeName Returns subtype variable for your control

    a = Cint(1)
    b = Cstr(1)

    Response.Write(TypeName(a)) & "<br>"
    Response.Write(TypeName(b))

    %>

  4. #4
    Join Date
    Apr 2008
    Posts
    4,089

    Re: How to convert string to int

    just use the Convert methods,, Convert.ToInt32(textbox1.text).the only valid conversion would be a string of the character codes for each character in a string.

Similar Threads

  1. Convert string into int in C
    By screwball in forum Software Development
    Replies: 4
    Last Post: 22-12-2011, 07:47 PM
  2. Convert XML string into DOM
    By GreatThinker in forum Software Development
    Replies: 6
    Last Post: 22-07-2010, 09:48 AM
  3. How to convert string into int in Java
    By Zool in forum Software Development
    Replies: 3
    Last Post: 09-11-2009, 11:41 AM
  4. Convert a string in decimal
    By FlayoFish in forum Software Development
    Replies: 3
    Last Post: 23-04-2009, 12:18 PM
  5. Convert a string to bytes
    By $tatic in forum Software Development
    Replies: 4
    Last Post: 18-02-2009, 01:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •