You could split the string on the \n character to get an array of name-value pairs, then find the one that starts with your search string ("Compression"), then split that on the : character and return the second part.
To generalize it, you could write a function that takes in your search string and the string to search, which returns the value for the specified name if found (or null if not found):
public static string GetValue(string name, string source)
{
if (source == null || name == null) return null;
var result = source.Split('\n')
.Select(i => i.Trim())
.FirstOrDefault(i => i.StartsWith(name + ":", StringComparison.OrdinalIgnoreCase))
?.Split(':');
return result?.Length == 2 ? result[1].Trim() : null;
}
Then you could call this with different "names" to find their values:
private static void Main()
{
var info = "ZipEntry: testfile.txt\n Version Made By: 45\n Needed to extract: 45\n" +
" File type: binary\n Compression: Deflate\n " +
"Compressed: 0x35556371\n Uncompressed: 0x1D626FBDB\n ...";
var compression = GetValue("Compression", info);
var zipEntry = GetValue("ZipEntry", info);
Console.WriteLine($"Compression = {compression}, ZipEntry = {zipEntry}");
GetKeyFromUser("\nDone! Press any key to exit...");
}
Output

Alternatively, you could write the method so it returns ALL the key/value pairs from the string in the form of a Dictionary<string, string>. Then you can lookup values by name:
public static Dictionary<string, string> GetNameValuePairs(string source)
{
return source?.Split('\n')
.Select(i => i.Split(':'))
.ToDictionary(k => k[0].Trim(), v => v.Length > 1 ? v[1].Trim() : null,
StringComparer.OrdinalIgnoreCase);
}
For example:
private static void Main()
{
var info = "ZipEntry: testfile.txt\n Version Made By: 45\n Needed to extract: 45\n" +
" File type: binary\n Compression: Deflate\n " +
"Compressed: 0x35556371\n Uncompressed: 0x1D626FBDB\n ...";
var keyValuePairs = GetKeyValuePairs(info);
// Write out all the name/value pairs found
foreach (var kvp in keyValuePairs)
{
Console.WriteLine($"{kvp.Key} = {kvp.Value}");
}
GetKeyFromUser("\nDone! Press any key to exit...");
}
Output

\nin the string not\r.replace = "Deflate\n Compressed: 0x35556371\n Uncompressed: 0x1D626FBDB\n .."I just wantDeflatestring.