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 exit
            Console.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# 浮点数十六进制字符串

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值