Skip to content

[API Proposal]: Convert.ToInt32 overload that takes a ROS<char> instead of a string #61397

Description

@carlossanlop

Background and motivation

I'm working on some code that contains fields that represent numbers in octal base, saved as ASCII characters.

To convert them to a ten base number, I need to do the following:

byte[]buffer=new[]{0x30,0x30,0x30,0x30,0x36,0x34,0x34,0x0};// 0000644\0stringstr=Encoding.ASCII.GetString(buffer.AsSpan());// "000644"inttenBaseNumber=Convert.ToInt32(str,fromBase:8);// 420

The third line is inefficient. Ideally, I should be able to pass a the string as a ReadOnlySpan<char>.

This can be a problem in my use case, because when I open a tar archive, I need to iterate through all the tar entries, and each entry header has multiple octal fields like the one above.

API Proposal

namespaceSystem{publicstaticclassConvert{publicstaticintToInt32(ReadOnlySpan<char>value,intfromBase);}}

API Usage

inttenBaseNumber=Convert.ToInt32(str.AsSpan(),fromBase:8);// 420

If this gets approved, I can work on adding this API.

cc @GrabYourPitchforks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions