Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Convert string to int
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { var strNumber = "123456789"; //Your code goes here var result = ConvertStringToInt(strNumber, 10); Console.WriteLine(result); } public static int ConvertStringToInt(string str, int baseNumber){ var len = str.Length; var result = 0; for(var i = 0; i < len; i++){ result += ConvertCharToInt(str[i]) * (int)Math.Pow(baseNumber, len - i - 1); } return result; } public static int ConvertCharToInt(char ch){ return (int)ch - 0x30; } } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
How to count the occurrence of each character in a string?
123
Rextester
Get Combined Placeholder Settings and New Content Length
Fórum ➡ Get all combinations for ▶different◀ Id's ( GroupBy version ) ♦
q1
Fibonacci and finding nth fibo number
Pentagon`s area
Length
PassByValue vs PassByRerefence
Please log in to post a comment.