字符串压缩算法(String compression algorithm)
String compression algorithm
I recently worked out a compression algorithm for strings, although there were some drawbacks. If the number of letters in the string is too high, the compression efficiency will be greatly reduced. This algorithm is designed primarily for compressing digital designs.
Now share the source code, and I hope everyone will make more comments.
Using System;
Namespace New919.Encrypt
{
/ / / <summary>
Improved algorithm of / / / before, using four digit string interception compression
/ / / </summary>
Public class CompressStr
{
/ / 64 hexadecimal dictionary
Private static, 2, 3, 4, 5, 6, 8, 9, A, C, D, E, F, G, I, J, K, L, H, M, strNumber, N, B,, O, string[],, P,, Q,, R, S, T",
"U", "W", "X", "V", "Y", "Z", "a", "B", "C", "e", "F", "g", "H", "I", "J", "K", "L", "m", "n", "O", "P", "Q", "R", "d", "s", "Z", "Y", "t", "X", "W", "U", "V", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" "",
"-", "/", "(", "")};
Private, static, string, strStringInString ="";
Private, static, string, strNumberInString ="";
#region compression method
#endregion
#region conversion to 64 hexadecimal method
Public, static, string, Compress (string, p_string)
{
/ / try
{/ /
Char[] charArrFirst = Separate (p_string).ToCharArray ();
#region first interception
String strConnectFirst ="";
String strConnectSecond ="";
String strConnectThird ="";
String strConnectFourth ="";
For (int i = charArrFirst.Length - 1; I > -1; I -) {
Int intTemp = (int) charArrFirst[i];
If (strConnectFirst.Length = 16)
{
/ / greater than 16 out of the loop
Break;
}
Else
{
/ / if (intTemp > = 48 && intTemp < = 57)
{/ /
StrConnectFirst = Convert.ToString (charArrFirst[i]) + strConnectFirst;
} / /
/ / else
{/ /
/ / break;
} / /
}
}
After the first take / digit string, the entire string left part
String strAfterFirst = p_string.Substring (0, p_string.Length - strConnectFirst.Length);
The first successful interception / finished, digital and letters section separation
#endregion
#region second interception, in the first interception on the basis of the strAfterFirst string at the end of the search for
digital characters
The first interception of the first judgment / digital string length is 16 bits, if it is the end of the letter, there may also be a digital character, further interception
If (strConnectFirst.Length = 16)
{
Section second interception / / digital
Char[] charArrSecond = strAfterFirst.ToCharArray ();
For (int i = charArrSecond.Length - 1; I > -1; I -)
{
Int intTemp = (int) charArrSecond[i];
If (strConnectSecond.Length = 16)
{字符串长度压缩
Break;
}
Else
{
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论