C# any method recognizing the number base?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



C# any method recognizing the number base?



I am not asking: "how to convert string to the integer knowing the base"



Quick question



I wrote my own one but just wondering if there is a method converting from the c# syntax string literal (ie "0x34", "0b101010" or "5675676") to the integer, automatically detecting the base. I have not found any, and I had to write my own one.



It is not the dupe as I am looking for the method which will automatically recognize the base (if it has the correct C# syntax of course). If I have to - there is no difference in writing the own one.



examples:



"0b1101010" - will convert it as 2 base string



"0x5454335" - will convert it as 16 base string



"34535534" - will convert it using 10 base string





string binary = Convert.ToString(5, 2); // convert 5 to its binary representation
– Matěj Štágl
Aug 10 at 12:14





As far a I know you need to manually handle each case
– harold
Aug 10 at 12:21





@harold I wrote the function as I have not found any, but I am just curious is any "standard" exists.
– P__J__
Aug 10 at 12:23





My understanding of the question is that he wants the actual number represented regardless of what base/format it's in. The .Net framework lacks any built in way to do this so it'd have to be done manually.
– PhonicUK
Aug 10 at 12:27





@MirjalalTalishinski Thank you very much, but I do not need it. I wrote (before asking) my own method. But was just curious if there is a "standard" one.
– P__J__
Aug 10 at 14:04









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS