Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 633735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:13:07+00:00 2026-05-13T20:13:07+00:00

How to find the position or location of string in given document.I have one

  • 0

How to find the position or location of string in given document.I have one word document and i want to store all its words and word positions in database so thats why i need to find the position of the words.

so please tell me how can i find position or location of word or string in given document.

i intend to use vb.net or c# for and .doc documents

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:13:07+00:00Added an answer on May 13, 2026 at 8:13 pm

    Mmmm… I haven´t found a more smart solution :-/ but maybe this helps you… We´ll suppose that you have some version of MS Office installed in your system.

    First of all, you have to add a reference in your project to a Microsoft COM component called “Microsoft Word ?* object library”

    *? It deppends of the version of your MS Office

    After you´ve added the reference, you could test this code:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Word;
    
    namespace ConsoleApplication1
    {
        class Program
        {
    
            static void Main(string[] args)
            {
    
                // Find the full path of our document
    
                System.IO.FileInfo ExecutableFileInfo = new System.IO.FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location);            
                object docFileName = System.IO.Path.Combine(ExecutableFileInfo.DirectoryName, "document.doc");
    
                // Create the needed Word.Application and Word.Document objects
    
                object nullObject = System.Reflection.Missing.Value;
                Word.Application application = new Word.ApplicationClass();
                Word.Document document = application.Documents.Open(ref docFileName, ref nullObject, ref nullObject, ref nullObject, ref nullObject, ref nullObject, ref nullObject, ref nullObject, ref nullObject, ref nullObject, ref nullObject, ref nullObject);
    
    
                string wholeTextContent = document.Content.Text; 
                wholeTextContent = wholeTextContent.Replace('\r', ' '); // Delete lines between paragraphs
                string[] splittedTextContent = wholeTextContent.Split(' '); // Get the separate words
    
                int index = 1;
                foreach (string singleWord in splittedTextContent)
                {
                    if (singleWord.Trim().Length > 0) // We don´t need to store white spaces
                    {
                        Console.WriteLine("Word: " + singleWord + "(position: " + index.ToString() + ")");
                        index++;
                    }
                }
    
                // Dispose Word.Application and Word.Document objects resources
    
                document.Close(ref nullObject, ref nullObject, ref nullObject);
                application.Quit(ref nullObject, ref nullObject, ref nullObject);
                document = null;
                application = null;
    
                Console.ReadLine(); 
            }
        }
    }
    

    I´ll test it and it looks that it works =)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have around 1,000,000 users. I want to find out what position
I have a RichTextBox and I need to find the position of the vertical
I have a List with numbers, and I'd like to find the position of
I need to find out the pixel position of one element in a list
I have a component that changes its location based on other elements. I'm trying
I'm currently wanting to find out an XMLNode from a text location. I have
I am trying to find the Starting location/position of the JFrame in order to
I am trying to have a constant gps listener that will send its location
I have a google map set up to find the user's current location, and
What would be the quickest way to find the position of a member in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.