Viyi.Strings 是从 Viyi.Util 中分离出来的,专注于处理字符串相关内容的一个库。目前主要提供对二进制数据进行十六进制编/解码和 Base64 编/解码。将来会提供更多的字符串工具。
English [en]
Viyi.Strings is a library separated from Viyi.Util, which focuses on processing strings. At present, Viyi.Strings supplies Base64 and Hex encoding/decoding by extension methods, as well as a text encoding/decoding framework. More string tools will be available in the future.
Viyi.Strings 使用木兰宽松许可证第 2 版(Mulan Permissive Software License, Version 2)。
原 Viyi.Util 涉及的范围非常多,过于分散,而且其中部分工具已经有更好的替代品。所以没有对 Viyi.Util 直接进行升级,而是将其拆分:
- Viyi.Strings 用于处理字符串 (Viyi.Strings is a string toolkit.)
- Viyi.Bytes 用于处理二进制数据,计划中 (Viyi.Bytes is a binary data toolkit, in planning.)
Viyi.Strings 发布在 NuGet 上,在 Visual Studio 中可以使用 [NuGet Package Manager][vs_nuget] 安装,也可以在 Powershell Manager 命令行安装:
Install-Package Viyi.Strings
或通过 .NET CLI 安装:
dotnet add package Viyi.Strings
或使用其他 NuGet 支持的方式进行安装。
源代码托管在 gitee.com 上:传送门 (Follow this link to source codes)
基于文本的编/解码主要依据 [RFC-4648 (rfc-editor.org)][rfc_4648]。
Base 64 编/解码:EncodeBase64()
/DecodeBase64()
Base 64 Url 编/解码:EncodeBase64Url()
/ DecodeBase64Url()
兼容 Base 64 和 Base 64 Url 的解码:DecodeBase64Compatible()
Base 16(十六进制)编/解码:EncodeBase16()
/DecodeBase16()
EncodeHex()
/DecodeHex()
Base 32 编/解码:EncodeBase32()
/DecodeBase32()
EncodeBase32Hex()
/ DecodeBase32Hex()
Utf8 编/解码:EncodeUtf8()
/DecodeUtf8()
使用
System.Text.Encoding.UTF8
实现
其他 Encoding 编/解码快捷调用扩展方法:Encode()
/Decode()
TextCodec
管理各心及抽象化接口
IsEmpty()
和 IsSpaces()
灵活判断
IsNotEmpty()
和 IsNotSpaces()
EmptyAs()
和 SpacesAs()
灵活赋予默认值CamelCase()
/PascalCase()
/KebabCase()
/SnakeCase()
扩展方法CaseTo(string)
扩展方法按自定义规则转换CaseConvert
注册中心和 ICaseConverter
接口ToString(int radix)
ToInt32(int radix)
/ToUInt32(int radix)
ToInt64(int radix)
/ToUInt64(int radix)
ToInt32(true)
/ ToUInt32(true)
/ ToInt64(true)
/ ToUInt64(true)
解析带 "0x"
前缀的十六进制数。 解析为布尔值,灵活支持 on/off
、yes/no
及其他字符串内容
ToBoolean()
系列扩展方法CreatePredicator()
工具方法创建断言函数数字范围生成/解析
在 #1~10#,#25,#30~#35
这种形式的范围表示法和 int[]
之间进行转换,允许自定义分隔符、连字符和标号前缀。
NumsRange.Parse()
/ new NumsRange().Parse()
NumsRange.ToRangeString()
注意:
ToRangeString()
不会对数据源进行排序,若有必要请先调用OrderBy()
扩展方法排序。
Human Readable Size 表示
将整数表示的存储容量大小(字节/位)处理成对人类友好,易于识别的,带 K、M、G 等单位的格式。
(ulong/long/uint/int).ToReadableSize(Action<Options>? config = null)
Options
或 Action<Options>
配置
B
或 b
,或者其他K, M, G, ...
或其他1024
或 1000
作为除数 解析表示时间长度的字符串,如 5m
、2hours
等
string.ToTimeSpan(string defaultUnit = "m")
m/minutes
)、小时 (h/hours
)、秒 (s/seconds
)、天 (d/days
)、周 (w/weeks
) 及毫秒 (ms/milliseconds
) 等对 FormattableString 预先进行一次格式化处理
在使用 ExecuteSqlInterpolated()
前可以使用 PreFormat
预先处理掉不是 SQL 参数的插值(比如表名)。
FormattableString
的 PreFormat()
扩展如果您有新的想法或者发现 BUG,请在 Issue 系统中提出来,经过讨论之后确定是否添加/修改,以及如何进行。
如果您愿意贡献代码,请 Fork 本库,从 develop
分支创建功能/BUG/任务分支,根据 Issue 修改之后,向 develop
分支提起 PR。
非常感谢各位的支持和贡献!
[rfc_4648]: https://www.rfc-editor.org/rfc/inline-errata/rfc4648.html ""RFC-4648"" [argumentnullexception]: https://docs.microsoft.com/dotnet/api/system.argumentnullexception "ArgumentNullException" [argumentexception]: https://docs.microsoft.com/dotnet/api/system.argumentexception " ArgumentException" [notsupportedexception]: https://docs.microsoft.com/dotnet/api/system.notsupportedexception "NotSupportedException" [vs_nuget]: https://docs.microsoft.com/zh-cn/nuget/consume-packages/install-use-packages-visual-studio
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型