locked
convert string to int RRS feed

  • Question

  • User-2060576634 posted

    hi everybody. how can i convert this string to int without writing another line. i mean without defining another var:

    debtamount = Request.Form["debtamount"];

    Tuesday, June 2, 2015 5:59 PM

Answers

  • User-352524747 posted
    debtamount = Request.Form["debtamount"].AsInt();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 2, 2015 6:05 PM
  • User2103319870 posted

    mdehghani

    hi everybody. how can i convert this string to int without writing another line. i mean without defining another var:

    debtamount = Request.Form["debtamount"];

    Have you used Convert.ToInt32() method if not try with the below code

    int debtamount = Convert.ToInt32(Request.Form["debtamount"].ToString());

    EDIT: Sorry I didn't noticed that you have asked for WebMatrix. The code which I provided may not work.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 2, 2015 6:07 PM
  • User281315223 posted

    There are a few ways to handle this in .NET and WebMatrix and all of them function basically the same.

    Int32.Parse()

    debtamount = Int32.Parse(Request.Form["debtamount"]);

    Convert.ToInt32()

    debtamount = Convert.ToInt32(Request.Form["debtamount"]);

    AsInt()

    debtamount = Request.Form["debtamount"].AsInt();

    The first two approaches are primarily used in traditional .NET applications, however the last one, AsInt() is something that was included within WebMatrix. All of these should work, so it's up to you as to which you find easiest to use.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 2, 2015 6:24 PM

All replies

  • User-352524747 posted
    debtamount = Request.Form["debtamount"].AsInt();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 2, 2015 6:05 PM
  • User2103319870 posted

    mdehghani

    hi everybody. how can i convert this string to int without writing another line. i mean without defining another var:

    debtamount = Request.Form["debtamount"];

    Have you used Convert.ToInt32() method if not try with the below code

    int debtamount = Convert.ToInt32(Request.Form["debtamount"].ToString());

    EDIT: Sorry I didn't noticed that you have asked for WebMatrix. The code which I provided may not work.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 2, 2015 6:07 PM
  • User281315223 posted

    There are a few ways to handle this in .NET and WebMatrix and all of them function basically the same.

    Int32.Parse()

    debtamount = Int32.Parse(Request.Form["debtamount"]);

    Convert.ToInt32()

    debtamount = Convert.ToInt32(Request.Form["debtamount"]);

    AsInt()

    debtamount = Request.Form["debtamount"].AsInt();

    The first two approaches are primarily used in traditional .NET applications, however the last one, AsInt() is something that was included within WebMatrix. All of these should work, so it's up to you as to which you find easiest to use.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 2, 2015 6:24 PM