我试图在C#中截断一些长文本,但我不希望我的字符串在一个单词中被切断.有没有人有一个我可以用来截断单词结尾的字符串的函数?
例如:
"This was a long string..."
Run Code Online (Sandbox Code Playgroud)
不:
"This was a long st..."
Run Code Online (Sandbox Code Playgroud) 我知道已经存在一个帖子,描述几乎相同,但我认为我的有点不同.
我想知道的是如何在分配命名空间方面组织扩展方法.目前 - 对于我们框架中的扩展方法 - 我使用以下命名空间模式
在里面我有扩展方法类.这对我来说很好,但缺点是我们的软件开发人员无法立即看到扩展器.考虑我有一个StringExtender类的情况,它提供了一个非常方便的扩展方法"In",它扩展了String对象.使用带有上述命名空间的扩展方法,我们的程序员除非明确包含其命名空间,否则不会看到扩展方法.相反,如果我将扩展方法放在System命名空间中,每个人都会立即看到它,但我读到这是不好的做法.
所以我的问题是你如何推广你的开发人员使用的扩展方法.
例如:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>title</title>
</head>
<body>
<a href="aaa.asp?id=1"> I want to get this text </a>
<div>
<h1>this is my want!!</h1>
<b>this is my want!!!</b>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
结果是:
I want to get this text
this is my want!!
this is my want!!!
Run Code Online (Sandbox Code Playgroud)