Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

match the word from text file

 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
hi all,

i have an input like this in the text file

located 1
biosphere 2
reserve 3


in this i want to find if the text file has the word located. It should match the word and display the result as 1. How to do like that ? Help me...

 
Ranch Hand
Posts: 91
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
You can do the following:
1) you input the text file, use readLine() to read the lines in the text file one by one.
2) after that you can use stringTokenizer class. You get two tokens at each line.
3) Store the tokens in a data structure. for eg tree map: TreeMap<String, Integer> = new TreeMap<String, Integer>();
4) once you have all the values in the tree map, you can just get the value for a particular string. The map would have entires like: Located, 1 ; biosphere 2 and so on.
So for Located you will get the value 1.

I did this for my project. I had a text file with some numerical values which were required for some calculation. So i read the file, used StringTokenizer to get the tokens and stored them in the tree map.

 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

deepika deepi wrote: i have an input like this in the text file


Deepika, this is a duplicate of this thread. Please don't double-post.

Locking this one.

Winston
 
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic