开发者

Custom Server Control, Text Property Whitespace

I am creating a custom server control with a property that accepts a String as input. What is the correct way to handle whitespace/tabs & newlines? For example,

<prefix:MyControl runat="server"
    Property="This is a long text string which is manually
              wrapped in the VS text editor on multiple
              lines."
>
</prefix:MyControl>
开发者_如何学Python

This returns something similar to

"This is a long text string which is manually\r\n           wrapped in the VS text editor on multiple\r\n           lines."

Is there a special attribute I can apply to the propery to help with this? I have checked Metadata Attributes for Custom Server Controls Or do I need to manually strip the linebreaks and extra spacing?


Discovered a Regular Expression solution which finds multiple whitespace characters preceded by a line break and replaces matches with a single space.

private string property;

[Bindable(true)]
public string Property {
    get { return property; }
    set {
        property = Regex.Replace(value, @"(\n|\r|\r\n)\s+", " ");
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜