Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Convert a string to Integer in C# without library function

public static void Main() {
    string str = Console.ReadLine();
    int j = 0;
    int myNumber = 0;
    string strReverse =String.Empty;

    //Reverse the string
    foreach (char temp in str)
    {
        strReverse = temp + strReverse;
    }

    foreach (char temp in strReverse)
    {
        int i = temp - 48; //Ascii character
        myNumber = myNumber + i * myPower(10,j);
        j++;
    }
    Console.WriteLine(myNumber);
    Console.ReadLine();
}


public static int myPower(int i, int j)
{
    int final = 1;
    for (int loop =0 ; loop < j; loop++)
        final = final  * i;
    return final;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: linq while loop in c# 
Csharp :: c# generate insert statement from object 
Csharp :: shuffle array c# 
Csharp :: ExpandoObject Add PropertyName and PropertyValue Dynamically 
Csharp :: IOException: Failed to prepare target build directory. Is a built game instance running? UnityEditor.WindowsStandalone.WindowsDesktopStandalonePostProcessor.DeleteDestination (UnityEditor.Modules.BuildPostProcessArgs args) 
Csharp :: scaffolding in vs22 asp.net 6 
Csharp :: wpf binding to static property in code behind 
Csharp :: c# bool? to bool 
Csharp :: how to c# 
Csharp :: C# wpf show hidden window 
Csharp :: technische vragen c# 
Csharp :: how to subtract two rows asp ne gridview in asp.net 
Csharp :: c# entity mvc get user from razor layout 
Csharp :: c# accept any enum 
Csharp :: Get single listView SelectedItem 
Csharp :: how to combine constructors in c# 
Csharp :: C# program to find sum of array elements 
Csharp :: wpf ope another project page 
Csharp :: How to create a gameobject by code 
Csharp :: how to controller request in c# 
Csharp :: params string[] 
Csharp :: asp.net core get current culture in controller 
Csharp :: what is the difference between rotation rotation axis and equator 
Csharp :: c# ile ürün çekme - htmlagilitypack 
Csharp :: c# remove numericUpDown white space 
Csharp :: c# inject dll into process 
Csharp :: wpf repository pattern query async with includes properties 
Csharp :: how to make game restart when player touches a object unity 
Csharp :: C# signup code 
Csharp :: array hw exercise 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =