Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

convert a string to an integer without using library

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 :: datagridview mouse click event c# 
Csharp :: unity how to change visual studio version 
Csharp :: 1/1/1/1/1 
Csharp :: C# resize window without title bar 
Csharp :: convert relative path to physical path c# 
Csharp :: How to fill text with 2 different color/texture 
Csharp :: image into sql database 
Csharp :: c# get the return value of a func 
Csharp :: c# read csv file save to database dynamically 
Csharp :: unity check if animator has parameter 
Csharp :: Untiy particle system play 
Csharp :: unity 2d top down movement script 
Csharp :: WPF TextBox input to All Caps 
Csharp :: c# silent execute exe 
Csharp :: large blank file C# 
Csharp :: system.text.json ways to go about getting to the data how to get the data text.json you should use JsonDocument when 
Csharp :: c# one dimensional dictionary 
Csharp :: invalid length for a base-64 char array or string. frombase64string c#Add Answer 
Csharp :: antlr c# errors 
Csharp :: unity download image from online 
Csharp :: How to keep line breaks in SQL Server using ASP.NET and C#? 
Csharp :: C# Fibonacci list 
Csharp :: string to float c# 
Csharp :: how to change an object color with fill c# 
Csharp :: c# get buttons row and column in grid 
Csharp :: how to specify order of test in c# 
Csharp :: Unity SceneLoad by Name in Inspector 
Csharp :: send to main args dotnet debug 
Csharp :: button pervious for picturebox c# 
Csharp :: does Registry.CurrentUser.OpenSubKey create the key if it does not exist? 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =