# how to convert a numerical string to an integer value without using any in-built conversion functions in c# or java?

I have a numerical string variable as:
string in="4266";

Now, I want to convert this to an integer value as 4266, without using any in-built conversion functions such as: int.Parse().
I just want it to be solved by using the mathematical operators such as Division, Remainder..

Thanks.
Asked:
###### Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Euh... how can you make a division/remainder operation on a string ?
You need to convert it to a numerical value first... which is exactly your question .... have I missed something ?

I haven't done any C# for many years but isn't there a CINT() or VAL() kind of function to do that ?

0
High School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Does this qualify as a "solution"?

*Assuming only positive, whole integer values:
``````        private void button1_Click(object sender, EventArgs e)
{
string input="4266";
int output = StringToInt(input);
MessageBox.Show(input + " <== ? ==> " + output.ToString());
}

private int StringToInt(string input)
{
string digit;
int curValue;
int value = 0;
for (int i = 0; i < input.Length; i++)
{
digit = input.Substring(input.Length - (i + 1), 1);
curValue = "0123456789".IndexOf(digit);
value = value + (curValue * (int)Math.Pow(10, i));
}
return value;
}
``````
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Thanks.
This is what I wanted.
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.