Skip to content

Commit cf874f0

Browse files
committed
feat: 增加 upper 参数支持大小写
1 parent 54a14e8 commit cf874f0

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

src/extensions/BootstrapBlazor.Socket/DataConverter/HexConverter.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

5-
using System.Text;
6-
75
namespace BootstrapBlazor.Components.DataConverter;
86

97
/// <summary>
@@ -17,8 +15,9 @@ public static class HexConverter
1715
/// </summary>
1816
/// <param name="bytes">The byte array to convert.</param>
1917
/// <param name="separator"></param>
18+
/// <param name="upper"></param>
2019
/// <returns>A string containing the hexadecimal representation of the byte array.</returns>
21-
public static string ToString(byte[]? bytes, string? separator = "-")
20+
public static string ToString(byte[]? bytes, string? separator = "-", bool upper = true)
2221
{
2322
if (bytes == null || bytes.Length == 0)
2423
{
@@ -30,7 +29,7 @@ public static string ToString(byte[]? bytes, string? separator = "-")
3029
return BitConverter.ToString(bytes);
3130
}
3231

33-
return string.Join(separator, bytes.Select(i => Convert.ToString(i, 16)));
32+
return string.Join(separator, bytes.Select(i => upper ? i.ToString("X2") : i.ToString("x2")));
3433
}
3534

3635
/// <summary>

0 commit comments

Comments
 (0)