amoncada
amoncada

Reputation: 78

How to avoid split?

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;
}

Upvotes: 3

Views: 199

Answers (1)

Pete - MSFT
Pete - MSFT

Reputation: 4309

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.

Upvotes: 1

Related Questions