Reputation: 63
My application runs cmd commands and saves the output in a string. Whenever there is a german umlaut in the output, the content looks for example like this:
Id Name MainWindowTitle
14892 TextInputHost Microsoft Text Input Application
6712 VirtualBox Oracle VM VirtualBox Manager
2124 VirtualBoxVM Win10_2 [wird ausgef�hrt] - Oracle VM VirtualBox
How do i replace/remove the broken chars? like the �, because it doesnt let me encode the string in base64 without information loss.
string activeProcesses = SysHelper.GetForegroundProcesses(); //runs a cmd-process and returns the string with the broken character above
Upvotes: 0
Views: 163
Reputation: 63
Ok, so the problem was, that the "broken" char, prevented me from encoding the string to base64. If I did, the base64 string was broken and when decoding it, I received only alien signs.
I fixed it, by using
string processStrClean = Encoding.Default.GetString(Convert.FromBase64String(activeProcesses));
instead of
string processStrClean = Encoding.UTF8.GetString(Convert.FromBase64String(activeProcesses));
So, actually, it was the UTF8 encoding, which broke it. After using the Default encoding, I could encode the string into a base64 string and later decode it, without loss of information.
And always remember, kids, real heroes answer their own questions at stack overflow, once they find out the solution to their problem. Maybe someone finds this thread in 5 years and you save his day.
Upvotes: 1