最佳答案
正确,这个是.NET Framework的实现:
public string CharacterSet
{
get
{
this.CheckDisposed();
string contentType = this.m_HttpResponseHeaders.ContentType;
if ((this.m_CharacterSet == null) && !ValidationHelper.IsBlankString(contentType))
{
this.m_CharacterSet = string.Empty;
string str2 = contentType.ToLower(CultureInfo.InvariantCulture);
if (str2.Trim().StartsWith("text/"))
{
this.m_CharacterSet = "ISO-8859-1";
}
int index = str2.IndexOf(";");
if (index > 0)
{
while ((index = str2.IndexOf("charset", index)) >= 0)
{
index += 7;
if ((str2[index - 8] == ';') || (str2[index - 8] == ' '))
{
while ((index < str2.Length) && (str2[index] == ' '))
{
index++;
}
if ((index < (str2.Length - 1)) && (str2[index] == '='))
{
index++;
int num2 = str2.IndexOf(';', index);
if (num2 > index)
{
this.m_CharacterSet = contentType.Substring(index, num2 - index).Trim();
}
else
{
this.m_CharacterSet = contentType.Substring(index).Trim();
}
break;
}
}
}
}
}
return this.m_CharacterSet;
}
}
回答时间:2010-7-21 13:24:23
| 回答者:
56max