如何避免分裂?
我在文档中有这样的文字:“50%”;当我运行这个函数时,它只返回“50”,之后返回“%”。我不知道为什么它会分割 % 的 50...您能否告诉我如何避免这种行为以获得完整的单词“50%”,而不是“50”和“%”?
int astart = 0;
int aend = Doc.Content.End;
//docwords.Words = '50%'
Range docwords = Doc.Range(ref astart, ref aend);
foreach (Range word in docwords.Words)
{
// here first return "50" and after return "%"
String wordText = word.Text;
}
I have this text in the document:"50%"; when I run this function it just returns "50" and after that it returns "%". I dont know why it is spliting the 50 of the %... Can you please tell me how can I avoid this behavior in order to get the complete word "50%", instead "50" and "%"?
int astart = 0;
int aend = Doc.Content.End;
//docwords.Words = '50%'
Range docwords = Doc.Range(ref astart, ref aend);
foreach (Range word in docwords.Words)
{
// here first return "50" and after return "%"
String wordText = word.Text;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您正在使用 Office10 和 Word API。基于此@Richard 是正确的。单词会因标点符号、空格或行首或行尾而被中断。
如果您想避免拆分,您最好使用正则表达式和匹配集合来选择单词。像
Regex.Matches(Document.Text, @"[A-Za-z0-9]+")
这样的东西可能会有所帮助。 (并将所需的标点符号粘贴到方括号中。I'm presuming you're using Office10 and the Word API. Based on this @Richard is correct. Words are broken by punctuation, a space, or being at the start or end of a line.
If you want to avoid the split you may be better off selecting your words using a RegEx and Matches collection. Something like
Regex.Matches(Document.Text, @"[A-Za-z0-9]+")
may help. (And stick the punctuation that you want into the square brackets.