C# 将字符串转换为十六进制值示例
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication15 { class Program { static void Main(string[] args) { string str = "Onitroad!"; char[] counting = str.ToCharArray(); foreach (char words in counting) { int value = Convert.ToInt32(words); string hexaOutput = String.Format("{0:X}", value); Console.WriteLine("Hexadecimal value of {0} is {1}", words, hexaOutput); } Console.ReadLine(); } } }
在本文中,我们正在讨论如何为字符串中的每个字符获取相应的十六进制值。
要首先执行此操作,我们将使用Cand的ToCharArray()方法将字符串转换为字符数组,然后我们将存储在数组的字符中。
从我们将通过foreach循环取自一个字符,然后获取字符的代码值。
在字符串形式中将十进制值转换为十六进制值之后,我们将使用字符串类的格式方法。
日期:2020-04-11 22:50:33 来源:oir作者:oir