• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to capture a string from a file

 
Vishnu Mittal
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a lot of text files and i want to capture the string that comes after a specific piece of text in each files.for ex-

I have file file1.txt

23d:retd//ysdussds
20c:abcd//aggds215
12d:fsrs/ydwtttww

file2.txt

23d:retd//yewew
20c:abcd//asdfqwer
12d:nhsu/ydweww

so i want to capture the text after 20c:abcd// and stoe it in a variable.
Please help me in this matter.

Thanks and Regards,
Vishnu
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch
Use regular expression for that. By looking at the content of the file, we can infer some sort of pattern. The easiest way is to split the String with "/+" as a pattern and get only the second element.

I'll leave the Java code to you as an exercise
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!