Truncate string on whole words in .NET C#

前端 未结 10 1372
走了就别回头了
走了就别回头了 2020-11-29 22:43

I am trying to truncate some long text in C#, but I don\'t want my string to be cut off part way through a word. Does anyone have a function that I can use to truncate my st

10条回答
  •  猫巷女王i
    2020-11-29 23:15

    If you are using windows forms, in the Graphics.DrawString method, there is an option in StringFormat to specify if the string should be truncated, if it does not fit into the area specified. This will handle adding the ellipsis as necessary.

    http://msdn.microsoft.com/en-us/library/system.drawing.stringtrimming.aspx

提交回复
热议问题