I run the PowerShell command to get total RAM capacity using C# and it returns this value. @{TotalPhysicalMemory= 17856325}. I wrote a code to get the only integer value. This is the code.
string ramSize = "@{TotalPhysicalMemory= 17856325}";
string ramValue = ramSize.Split('=')[1].Split('}')[0].Trim().ToString();
This code returns the integer value. But I want to know are there any ways to get this integer value easily?
\dcharacter class elementTotalPhysicalMemoryproperty. You should request that property directly. If you're dealing with the string rendering of that object, you lost the advantage well before this point.\dto the search, and C# for good luck. My search turned up learn.microsoft.com/en-us/dotnet/standard/base-types/…, a very good link. Then in the left hand pain, there's a link to the "Overview" topic: learn.microsoft.com/en-us/dotnet/standard/base-types/…. Between the two, you should be able to figure things out. Pulling a number from a string is one of the basic RegEx examples. Enjoy learningint. Use alonginstead.