c# 浮点数十六进制字符串_从C#中包含十六进制值的字符串数组中打印整数值...
c# 浮點數十六進制字符串
將十六進制字符串數組轉換為整數 (Converting array of hexadecimal strings to integers)
Let suppose you have some of the strings (i.e. array of strings) containing hexadecimal values like "AA", "ABCD", "ff21", "3039", "FAFA" which are equivalent to integers 170, 43981, 65313, 12345, 64250.
假設您有一些字符串(即字符串數組)包含十六進制值,例如“ AA”,“ ABCD”,“ ff21”,“ 3039”,“ FAFA” ,它們等效于整數170、43981、65313、12345, 64250 。
As we have written in the previous post: convert hexadecimal string to integer, we use Convert.ToInt32() function to convert the values.
正如我們在上一篇文章中所寫的: 將十六進制字符串轉換為integer ,我們使用Convert.ToInt32()函數轉換值。
We will access each item using a foreach loop, and convert the item to an integer using base value 16.
我們將使用foreach循環訪問每個項目,并使用基值16將其轉換為整數。
Code:
碼:
using System; using System.Text;namespace Test {class Program{static void Main(string[] args){string[] str = { "AA", "ABCD", "ff21", "3039", "FAFA"};int num = 0;try{//using foreach loop to access each items//and converting to integer numbers foreach (string item in str){num = Convert.ToInt32(item, 16);Console.WriteLine(num);}}catch (Exception ex){Console.WriteLine(ex.ToString());}//hit ENTER to exitConsole.ReadLine();}} }Output
輸出量
170 43981 65313 12345 64250翻譯自: https://www.includehelp.com/dot-net/print-integer-values-from-an-array-of-strings-containing-hexadecimal-values-in-c-sharp.aspx
c# 浮點數十六進制字符串
總結
以上是生活随笔為你收集整理的c# 浮点数十六进制字符串_从C#中包含十六进制值的字符串数组中打印整数值...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 双向tvs和单向tvs_TVS的完整形式
- 下一篇: 旅行商问题