Hi Guys,

I'm writing a program for work which uses the HtmlTextWriter to output html files (it's a reporting system). In each file I want to render a style tag at the beginning and to do this I'm using the HtmlTextWriterStyle enumeration.

This means I need to convert any value belonging to this enumeration into its equivalent html formatted string. Ideally, I'd like to make use of the GetStyleName function in HtmlTextWriter, but that's a private function :(.

Note: The enumerations ToString function doesn't convert the styles to syntactically correct Html.

Cheers,

Anthony

In case anyone was wondering, I've just hacked together a solution for now... but it'd be nice if somebody came up with something cleaner... :P

System::String^ HtmlStyle::GetStyleString(System::Web::UI::HtmlTextWriterStyle style)
{
  String^ str = style.ToString();  

  // Skip the first char
  for(int i = 1; i < str->Length; i++)
  {
    if(System::Char::IsUpper(str[i]))
    {
      str = str->Insert(i, "-");
      i++;
    }
  }
  return str->ToLower();
}

This solution assumes that for every upper case letter in a style (the string versions are always something like FontSize) bar the first, will have a dash before them in the syntactically correct Html.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.