Thanks:  0
Likes:  0
Dislikes:  0

# Thread: finding distance b/w 2 strings in word document!!

1. ## finding distance b/w 2 strings in word document!!

I want to find the distance between two strings that I provide in terms of number of words between them and I want this search to be performed in a word document. I am unable to do so. Can anyone please help/guide me in writing this script?

2. ## Re: finding distance b/w 2 strings in word document!!

Hi Vijay,

There are many scenarios possible in the given condition. For example, what if the given string exists multiple times.

3. ## Re: finding distance b/w 2 strings in word document!!

Enhance the below snippet to get content from Word.

<font class="small">Code:</font><hr /><pre>
strMainText = "want to find the distance between two strings that I provide in terms of number of words want to find the distance between two strings that I provide in terms of number of words"

strFirstWord = "distance"
strSecondWord = "words"

intFirstPos = Instr(strMainText, strFirstWord)
intSecPos = Instr(intFirstPos, strMainText, strSecondWord)

intLenBetween = intSecPos -(intFirstPos+Len(strFirstWord))

strTextInBetween = Mid(strMainText, intFirstPos+Len(strFirstWord), intLenBetween)

tempArray1 = Split(strTextInBetween)

tempArray = Split(Trim(strTextInBetween))

intNoOfWords = UBound(tempArray)
</pre><hr />

4. ## Re: finding distance b/w 2 strings in word document!!

Thanks Raj but the issue is that I have do this search inside word doc and I cannot assign the main text to any variable like you did you in your example.
That is one of the problem I am facing.

I will explain second issue by example:

If I am searching for Test near Comparison. Then, it should give me distance of each occurance of Test with each occurance of Comparison.

Suppose Test is appearing 2 times and Comparison is appearing 3 times in the word doc, then it should give me total of 6 distance counts between these 2 words.

Please help me in both these issues.

5. ## Re: finding distance b/w 2 strings in word document!!

Something like this might help you get the text from Word:

http://quicktestprofessional.wordpress.c...-word-document/

6. ## Re: finding distance b/w 2 strings in word document!!

Raj,

I am now using the following code with your example which is working fine

Set strRead=myfile.Content
strContents = objWord.CleanString(strRead.Text)

so that StrContents has all the contents of the file but I think there is a limit of string length that can be assigned to strcontents and full document content doesn't got searched this way....

Is there any workaround to this?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 9.68%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 12:34 PM.

Copyright BetaSoft Inc.