We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

What is the equivalent in C# of strtol function in C

Thread ID:

Created:

Updated:

Platform:

Replies:

267 May 18,2002 11:39 PM UTC May 19,2002 07:11 PM UTC WinForms 3
loading
Tags: FAQ
Mukesh Motwani
Asked On May 18, 2002 11:39 PM UTC

Empty

Clay Burch [Syncfusion]
Replied On May 19, 2002 06:18 AM UTC

You can use the static System.Int64.Parse method to convert a string to a signed 8-byte integer. In general, all the numeric types have this static Parse method. string s = "12345678"; long x = Int64.Parse(s); More generally, you can also use the System.Convert class to handle conversion among types.

Mukesh Motwani
Replied On May 19, 2002 10:06 AM UTC

System.Convert.ToInt64 works fine if there are no spaces. If I have a string like "128 128" and if the number of white spaces is not known using the code below in C, we can easily find the numeric variables. /*C code*/ char string="128 128",*ptr; NO_COL=strtol(string,&ptr,0); NO_ROW=atoi(ptr); The string is scanned up to the first character inconsistent with the base. Leading "white-space" characters are ignored. If the value of ptr is not (char **)NULL, a pointer to the character terminating the scan is returned in the location pointed to by ptr. Is there an equivalent function in C# which will tells us the index in the string where the first character inconsistent with the base is returned using the different Formating Types provided by C#. Thanks Mukesh > You can use the static System.Int64.Parse method to convert a string to a signed 8-byte integer. In general, all the numeric types have this static Parse method. > > string s = "12345678"; > > long x = Int64.Parse(s); > > More generally, you can also use the System.Convert class to handle conversion among types. > >

Clay Burch [Syncfusion]
Replied On May 19, 2002 07:11 PM UTC

If your whitespace is really spaces, then you could strip them out with code such as this. string s = "123 45678"; long x = Int64.Parse(s.Replace(" ", ""));

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;