oddszone
asked on
Regex Converting C# to C
I have a small function to compress a string so it is easy to transmit.
Basically long sequences of similar characters are substituted so for example.
0000000 11111 00000000000 22222222222222222222
becomes (ignore spaces)
A7A B5B A11A C20C
The C# is:
static string CompressMessage(string message)
{
return Regex.Replace(message, @"([0-7])\1{3,}", (Match m) => String.Format("{0}{1}{0}", (char)(m.Groups[1].Value[0 ] + 17), m.Value.Length));
}
Question:
I there an equivalent C library OR how easy is it to write this in C (for an embedded system)
Basically long sequences of similar characters are substituted so for example.
0000000 11111 00000000000 22222222222222222222
becomes (ignore spaces)
A7A B5B A11A C20C
The C# is:
static string CompressMessage(string message)
{
return Regex.Replace(message, @"([0-7])\1{3,}", (Match m) => String.Format("{0}{1}{0}",
}
Question:
I there an equivalent C library OR how easy is it to write this in C (for an embedded system)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thats fantastic. I just need to modify so it only substitutes when >3 chars in a row detected otherwise you add more characters to the output which defeats the object.
Ahhh, yes. I missed that little point, huh? Glad you can work with it and glad to help : )
Here is my stab at a C version. It's probably sloppy, but it should give you a start, I hope!
Yes, my C-Fu is not strong ; )
Open in new window