Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Search string using substring

Have Programming Question? Ask it here!
 
 
 


Akhilesh Chafale
Search string using substring
2 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


I want to print a string by searching a substring of that string. - i want to print email-ids from word files (resumes) in a directory. Search can be made using @ in the word file. So far i can find index position of @, that too in a single text file.

import java.io.*;

class FileRead { public static void main(String[] args) { String searchText = "@"; String fileName = "aa.doc"; StringBuilder sb = new StringBuilder();

    try
    {
        BufferedReader reader = new BufferedReader(new FileReader(fileName));

        //Reads until the end-of-file met
        while (reader.ready())
        {
            //Read line-by-line directly
            sb.append(reader.readLine());
        }
    }
    catch(IOException ex)
    {
        ex.printStackTrace();
    }

    String fileText = sb.toString();
    System.out.println("Position in file : " + fileText.indexOf(searchText));
}

}


Advertisement
View Answers

January 12, 2011 at 5:46 PM


Hello Friend,

Try the following code:

import java.io.*;
import java.util.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;

public class FileRead{
public static void main(String[] args) {
File file = null;
WordExtractor extractor = null ;
try {
file = new File("c:\\Hello.doc");
String st="";
FileInputStream fis=new FileInputStream(file.getAbsolutePath());
HWPFDocument document=new HWPFDocument(fis);
extractor = new WordExtractor(document);
String [] fileData = extractor.getParagraphText();
for(int i=0;i<fileData.length;i++){
if(fileData[i] != null)
st+=fileData[i]+" ";
}
StringTokenizer stk=new StringTokenizer(st," ");
while(stk.hasMoreTokens()){
String str=stk.nextToken();
if(str.indexOf('@')>0){
System.out.println(str);
}
}
}
catch(Exception exep){}
}
}

For the above code, you need apache poi library.

Thanks



January 16, 2011 at 11:16 PM


Thanks, the code was upto the mark.

Now, I want to scan all doc files in a directory and print all email ids.

I tried using these....

File directory = new File("C:/New Folder/"); String filename[] = directory.list();

  • and

File files[] = directory.listFiles(); for (File f : files) { // do whatever you want with each File f }

instead of file = new File("c:\Hello.doc");

but it didn't help.
Kindly help.



Related Tutorials/Questions & Answers:
Search string using substring
Search string using substring  I want to print a string by searching a substring of that string. - i want to print email-ids from word files (resumes) in a directory. Search can be made using @ in the word file. So far i can
string and substring
string and substring  bbbnnnmmm*ccc remove second asterick and display it as bbb*nnn mmm*ccc
Advertisements
string and substring
string and substring  my code is bbbnnnmmm*ccc how to remove the asterick at second position and display the code as bbb*nnn mmm*ccc
remove a substring from a string
remove a substring from a string  Please I jave an arraylist composed as follwoing [w1, w2, w3, w4, w1.w2.w3, w2.w3.w4, w3.w4, w2.w4, w1.w3, w1.w2] w2.w4 is a subset of w2.w3.w4 ?how I recognize it also w1.w3 is a subset
check if a substring exists in a string
check if a substring exists in a string  Please I jave an arraylist composed as follwoing [w1, w2, w3, w4, w1.w2.w3, w2.w3.w4, w3.w4, w2.w4, w1.w3, w1.w2] w2.w4 is a subset of w2.w3.w4 ?how I recognize it also w1.w3
String substring method example
.style1 { font-size: medium; } String substring() method example... a string. String class provide methods for finding substring from string. Method...:String = "Rose India"; var substring:String = str.substring(5,13
C String Substring
C String Substring       In this section, you will learn how to get the substring from a string in C. You can see in the given example, a string and a method substring
String substring(int beginIndex)
String substring(int beginIndex)   ... the substring(int beginIndex) method of String class. We are going to use substring(int beginIndex) method of String class in Java. The description of the code
find a substring by using I/O package
find a substring by using I/O package  Write a java program to find a sub string from given string by using I/O package
how to search for string using LIKE operator instead of integer?
how to search for string using LIKE operator instead of integer?  ... to search for itemid, then it shows "dbtable.jsp" file with 3 columns of itemid... in itemid. however, what i want to do is i want the user to search for the itemname
C get Substring from String
C get Substring from String       This section illustrates you how to get the substring using... have consider will as str2 and the whole string as str1. The function strstr
String substring(int beginIndex, int endIndex)
String substring(int beginIndex, int endIndex)  ... explanation about the substring(int beginIndex, int endIndex) method of String class. We are going to use substring(int beginIndex, int endIndex) method of String
NSMutableArray Search String
NSMutableArray Search String  Hi all, In my iPhone SDK application.. i wanted to search from the table data. My question is ..do i need to innsert the table data into search array? thanks
Java Substring
of String is called substring. Substrings are also a String. Substring is used... this method to find out the substring from a given String. substring() method... which is a substring of the current String. This method is written in two forms
PHP Array Sub String Search
PHP Array Search Sub-String In PHP if we need to search a sub-string within... PHP Search Array Substring Example 1: <?php $array1=array("...;The string: \"".$search."\" Found"; else  
JavaScript indexOf substring
; In this section, we are going to find the location of substring using... the parameters substring is the specified string and 0 is the index that will allow to start the search for the specified substring. Here is the code
write a java program for inserting a substring in to the given main string from a given position
write a java program for inserting a substring in to the given main string from a given position  write a java program for inserting a substring in to the given main string from a given position
SubString in Java
SubString(), a method of String class is used to get a part of original string.... If beginIndex is equal to length in SubString(int beginIndex) it will return empty String... String. Example of SubString in Java: import java.io.*; import
Substring in java
Substring in java   example:output 0f the code.. Input String:University of the Cordilleras Input Substring:of Output:1 ...use non static methods,don't use (.Substring).. ..please help me.. ..thank you.. deadline:November
Substring in java
Substring in java   example:output 0f the code.. Input String:University of the Cordilleras Input Substring:of Output:1 ...use non static methods,don't use (.Substring).. ..please help me.. ..thank you.. deadline:November
JPA Substring() Function
() function. The substring() function returns the some part of string arguments..., second is starting index and third is length of string . JPA Substring... JPA Substring() Function   
how to search the string arraylist contains database rows?
how to search the string arraylist contains database rows?  i need to search 2 database. one is excel database and another is SQL database. stored the row values into string arraylist. now i want to print the common rows existed
find and substring
String"); String findstring = keybord.readLine(); String substring = keybord.readLine(); findreplace(findstring,substring); } catch(IOException io...find and substring   **import java.io.BufferedReader; import
Auto Search box using ajax
Auto Search box using ajax   Hi , i want to implement auto search box functionality like google and linkedin using ajax,jsp,servlet, javascript etc.when the value appears on the textbox then we should also be able to select
How to perform search using AJAX?
How to perform search using AJAX?  Hi, I have following HTML code...; <td><label for="status">Search Status</td> <td><input..." value="Please enter search criteria"/></td> </tr> <tr>
search functionality using jsp from database
search functionality using jsp from database  search functionality using jsp from database
help with substring in c programing
. Please help with substring function,prompt the user for two strings and display whether or not the second string is a substring of the first string. Regards...help with substring in c programing  Hi I could not found programming
string palindrom using vbscript?
string palindrom using vbscript?  string palindrom using vbscript
How to substring in JQuery?
How to substring in JQuery?  Hi, I my JQuery application I am getting the value from server using Ajax. I have to substring the value in jQuery.... Please let's know How to substring in JQuery? Thanks   Hi
Use of <fn:subString(String, int, int)> Tag of JSTL
Use of <fn:subString(String, int, int)> Tag of JSTL... and return string type. Syntax : java.lang.String substring...; <c:out value="${fn:substring(string,start,end)}"/>
how to write a program to search a record using mvc2
how to write a program to search a record using mvc2   how can we write a code to search a record in table by using java bean as model, servlet as contoller and jsp as view
How to write a search functionality using javascript/jquery
How to write a search functionality using javascript/jquery   How to write a search functionality using javascript/jquery for ex: im searching "s" names it wil display "s" names
String indexOf method example
of the substring from the string. The indexOf() method start to search from beginning of the string and matching the substring from substring, if substring... .style1 { font-size: medium; } String indexOf() method example
SubString help - Java Beginners
System.out.println(strLine); String subString = str.substring(0); System.out.println("String after index: " + subString); subString...SubString help  Hi , I would appreciate if somebody could help me
Taking Substring
are using the substring() method to get certain characters from the big string... string. You will learn how to use the substring() method of String class... string with the help of substring() function of String class
how to search data in xml files using php
how to search data in xml files using php  So I want to create a website that allows me (or others) to type in a words and select a relevent search, and have it search multiple XML pages on server The XML documents are setup
How to using Binary Search Array Java ?
How to using Binary Search Array Java ?  Hi, I am beginners in Java Programming Language. I am trying to create small application using Array functions. The problem is that how to use binary search array in Java. Please give
JavaScript substring length
JavaScript substring length...; This section illustrates you how to determine the length of substring in JavaScript. You can see in the given example, we have defined a string and used the JavaScript
Auto complete of word search using ajax with java
Auto complete of word search using ajax with java  I want to display... using jsp to design the form. I want ajax sample to achieve this feature. Its like google search. Please help. Thanks in advance
Auto complete of word search using ajax with java
Auto complete of word search using ajax with java  I want to display... using jsp to design the form. I want ajax sample to achieve this feature. Its like google search. Please help. Thanks in advance
C Programming SubString Program
C Programming SubString Program  Sir I want to Check whether the Single Substring is present in the given 3 string. characters. eg if i entered First String- CPROGRAMMING Second String- CPROGRAM third String- PROGRAMMING if i
How to create binary search tree using an array?
How to create binary search tree using an array?  hello people, pls guide me on the topic above. i have an string array, i want to make a binary search tree based on data inside this array. the array contains names of people
Building Search Engine Applications Using Servlets !
Building Search Engine Applications Using Servlets Introduction This tutorial takes you through the process of building search engine using Java Servlets. You can Download the source code of search
Case-insensitive search using Hibernate Query Language(HQL).
Case-insensitive search using Hibernate Query Language(HQL).  What is Case-insensitive search using Hibernate Query Language
search
search  how to develop search box and how to retrive data from database..   Please visit the following link: Search box
Java SubString
; String class provides number of methods for manipulating the strings. substring... of the original string as String object. substring provides a way of making a copy of a piece of a String. This method has two forms: substring(int beginIndex): 
Passing a parameter using URL string
Passing a parameter using URL string  How to pass a parameter using the URL string in a JSF application
Search
Search   Hi, I have a project in which I am trying to enter "Marathi" (Indian local language) data in JSP using JSTL and trying to search data... and tries to search then It shows no data from database
SEARCH
SEARCH  how can we do search in jsp...? option for search criteria like name and DOB...   Please visit the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/servlets/search.shtml
read string - using loops in Java
read string - using loops in Java  Write a program to read a string composed of an unknown number of words, then count the number of words in the string, and Display the longest and shortest words, with first letter Uppercase
 

 

 

DMCA.com