I have a string like "sample". I need to get a string of it in hex format With DotNET from C/AL

Michele_GRS18
Member Posts: 5
Good morning everyone,
I need your help, I thank you in advance
I have a string like "sample". I need to get a string of it in hex format; like this:
%48%65%6C%6C%6F%20%57%6F%72%6C%64%21 <=> 'Hello World!'
I need a metod that let me Conversion from and to hexadecimal format. I'm programming on the Dynamics Nav 2015 platform.
Thank you so much in advance
Michele
I need your help, I thank you in advance
I have a string like "sample". I need to get a string of it in hex format; like this:
%48%65%6C%6C%6F%20%57%6F%72%6C%64%21 <=> 'Hello World!'
I need a metod that let me Conversion from and to hexadecimal format. I'm programming on the Dynamics Nav 2015 platform.
Thank you so much in advance
Michele
0
Best Answer
-
Slawek_Guzek wrote: »Why C/AL is not enough and you need .NET based solution?
FOR i := 1 TO STRLEN(InText) DO BEGIN //c, UpperByte, LowerByte : Integer //UpperByteChar, LowerByteChar : Char c := InText[i]; UpperByte := c DIV 16; LowerByte := c - (UpperByte * 16); IF LowerByte < 10 THEN LowerByteChar := 48 +LowerByte ELSE LowerByteChar := 87 +LowerByte; IF UpperByte < 10 THEN UpperByteChar := 48+UpperByte ELSE UpperByteChar := 87+UpperByte; HexText += STRSUBSTNO('%%1%2', UpperByteChar, LowerByteChar); END;
Because I prefer to exploit the potential that the dotNet platform offers, simply this. Thank you so much,
Michele
Source: https://docs.microsoft.com/it-it/dotnet/csharp/programming-guide/types/how-to-convert-between-hexadecimal-strings-and-numeric-types
string input = "Hello World!"; char[] values = input.ToCharArray(); foreach (char letter in values) { // Get the integral value of the character. int value = Convert.ToInt32(letter); // Convert the decimal value to a hexadecimal value in string form. string hexOutput = String.Format("{0:X}", value); Console.WriteLine("Hexadecimal value of {0} is {1}", letter, hexOutput); } /* Output: Hexadecimal value of H is 48 Hexadecimal value of e is 65 Hexadecimal value of l is 6C Hexadecimal value of l is 6C Hexadecimal value of o is 6F Hexadecimal value of is 20 Hexadecimal value of W is 57 Hexadecimal value of o is 6F Hexadecimal value of r is 72 Hexadecimal value of l is 6C Hexadecimal value of d is 64 Hexadecimal value of ! is 21 */
0
Answers
-
HtmlEncode method of the HttpUtility calss doesn't allow to convert the whole string in hexadecimal format but converts only a part of it
Thank you so much in advance
Michele0 -
Are there any other updates?
Thank you so much in advance
Michele0 -
Why C/AL is not enough and you need .NET based solution?
FOR i := 1 TO STRLEN(InText) DO BEGIN //c, UpperByte, LowerByte : Integer //UpperByteChar, LowerByteChar : Char c := InText[i]; UpperByte := c DIV 16; LowerByte := c - (UpperByte * 16); IF LowerByte < 10 THEN LowerByteChar := 48 +LowerByte ELSE LowerByteChar := 87 +LowerByte; IF UpperByte < 10 THEN UpperByteChar := 48+UpperByte ELSE UpperByteChar := 87+UpperByte; HexText += STRSUBSTNO('%%1%2', UpperByteChar, LowerByteChar); END;
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-031 -
Slawek_Guzek wrote: »Why C/AL is not enough and you need .NET based solution?
FOR i := 1 TO STRLEN(InText) DO BEGIN //c, UpperByte, LowerByte : Integer //UpperByteChar, LowerByteChar : Char c := InText[i]; UpperByte := c DIV 16; LowerByte := c - (UpperByte * 16); IF LowerByte < 10 THEN LowerByteChar := 48 +LowerByte ELSE LowerByteChar := 87 +LowerByte; IF UpperByte < 10 THEN UpperByteChar := 48+UpperByte ELSE UpperByteChar := 87+UpperByte; HexText += STRSUBSTNO('%%1%2', UpperByteChar, LowerByteChar); END;
Because I prefer to exploit the potential that the dotNet platform offers, simply this. Thank you so much,
Michele0 -
Slawek_Guzek wrote: »Why C/AL is not enough and you need .NET based solution?
FOR i := 1 TO STRLEN(InText) DO BEGIN //c, UpperByte, LowerByte : Integer //UpperByteChar, LowerByteChar : Char c := InText[i]; UpperByte := c DIV 16; LowerByte := c - (UpperByte * 16); IF LowerByte < 10 THEN LowerByteChar := 48 +LowerByte ELSE LowerByteChar := 87 +LowerByte; IF UpperByte < 10 THEN UpperByteChar := 48+UpperByte ELSE UpperByteChar := 87+UpperByte; HexText += STRSUBSTNO('%%1%2', UpperByteChar, LowerByteChar); END;
Because I prefer to exploit the potential that the dotNet platform offers, simply this. Thank you so much,
Michele
Source: https://docs.microsoft.com/it-it/dotnet/csharp/programming-guide/types/how-to-convert-between-hexadecimal-strings-and-numeric-types
string input = "Hello World!"; char[] values = input.ToCharArray(); foreach (char letter in values) { // Get the integral value of the character. int value = Convert.ToInt32(letter); // Convert the decimal value to a hexadecimal value in string form. string hexOutput = String.Format("{0:X}", value); Console.WriteLine("Hexadecimal value of {0} is {1}", letter, hexOutput); } /* Output: Hexadecimal value of H is 48 Hexadecimal value of e is 65 Hexadecimal value of l is 6C Hexadecimal value of l is 6C Hexadecimal value of o is 6F Hexadecimal value of is 20 Hexadecimal value of W is 57 Hexadecimal value of o is 6F Hexadecimal value of r is 72 Hexadecimal value of l is 6C Hexadecimal value of d is 64 Hexadecimal value of ! is 21 */
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions