- Home /
Convert String to int
Hi ,
I have a cavas with an inputField, But i want to store the string of the inputfield into an int. ( lets say the strings is "10" , I want that string to be converted to an int) I've found some solution on the internet about a function called convert.int32(string) but whenever i type the function' Convert' into monoDevelop it doesn't recognize it. Maybe I explained it bad , but here is the code i'm struggling with :
public List<int> WageOfPlayer = new List<int> ();
public List <InputField> AmountOfCoins = new List<InputField> ();
void Start () {
WageOfPlayer [0] = AmountOfCoins [0].text;
// I want to convert the text of amount of coins into an int so that i can store it in the WageOfPlayer list so i can make calculations with it
}
Thank you in advance.
Answer by DoTA_KAMIKADzE · May 23, 2015 at 08:34 PM
To use Convert.ToInt32 method you should either use system:
using System;
//and then:
Convert.ToInt32(yourString);
or if you don't want then you can just call it like that:
System.Convert.ToInt32(yourString);
Also you can use int.Parse, or int.TryParse (especially if you're not sure what user can input and you haven't bothered to check before parsing).
Your answer
![](https://koobas.hobune.stream/wayback/20220613200209im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can I create a list with an int/float and a string? C# 2 Answers
A node in a childnode? 1 Answer
How to Detect Touch on a Random String from a List? 1 Answer
Extract number from string? 3 Answers