G
Guest
hey all
currently i use the following piece of code to check if the string passed to
me can be converted to base64, it is not very efficient and bad, can someone
please suggest another of doing this
private string ConvertBase64ToString(string[] content)
{
StringBuilder sb = new StringBuilder();
int i = content.GetUpperBound(0);
for (int j=0; j<i; j++)
{
try
{
// if successful in converting base64 append it
sb.Append(ASCIIEncoding.ASCII.GetString(Convert.FromBase64String(content.GetValue(j).ToString())));
}
catch (Exception)
{
// cannot be decoded so append the original string
sb.Append(content.GetValue(j).ToString());
}
}
return sb.ToString();
}
content passed to be looks like:
----
some string not containing base64
another strign without base64
base64base64base64stuffhere
morebase64base64stuffhere
some more strings without base64
----
is it possible to somehow find out if a line is base64 without attempting to
covert it and catching the exception?
thanks
currently i use the following piece of code to check if the string passed to
me can be converted to base64, it is not very efficient and bad, can someone
please suggest another of doing this
private string ConvertBase64ToString(string[] content)
{
StringBuilder sb = new StringBuilder();
int i = content.GetUpperBound(0);
for (int j=0; j<i; j++)
{
try
{
// if successful in converting base64 append it
sb.Append(ASCIIEncoding.ASCII.GetString(Convert.FromBase64String(content.GetValue(j).ToString())));
}
catch (Exception)
{
// cannot be decoded so append the original string
sb.Append(content.GetValue(j).ToString());
}
}
return sb.ToString();
}
content passed to be looks like:
----
some string not containing base64
another strign without base64
base64base64base64stuffhere
morebase64base64stuffhere
some more strings without base64
----
is it possible to somehow find out if a line is base64 without attempting to
covert it and catching the exception?
thanks