how to change variable's type? MC++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Napcrisis
    New Member
    • Sep 2008
    • 8

    how to change variable's type? MC++

    Hi
    i need to change a variables' type from String to Int in managed c++ but dunno how to. Do any1 know how i can do this?
    Regards
    Tom
  • misza
    New Member
    • Feb 2008
    • 13

    #2
    Provided that the string contains a valid integer you can use this:
    int yourint = System::Convert ::ToInt32(yours tring);

    You can also use this, which is i guess an even better option:
    int yourint;
    if(System::Int3 2::TryParse(you rstring, yourint))
    {
    // do sth with the int <yourint>
    }
    else
    {
    // the string is not a valid int
    }

    hope that helps,
    michal

    Comment

    Working...