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 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));
}
}
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();
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.
Ads
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
Advertisements
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
How to check if a string contains a substring in iOS?
Function for checking the presence of a
substring in a
string (NSString... the
presence of
substring in a
string (NSString) and there is no readymade function... of a
substring in a
string. This function will simply tell
you if NSString object
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
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
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
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
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
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
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
 
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>
How to substring in Java?
How to
substring in Java? Hi,
I want to get a part of
String... the
substring() method of Java for getting a part of
string based on the index number passed to
substring() function.
Here is an example:
String string = "Deepak Kumar
String Reverse Using StringUtils
String Reverse
Using StringUtils
In this example we are going to reverse a given
string
using StringUtils api.
In this example we are reversing a
string and the reversed
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
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
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