当前位置: 动力学知识库 > 问答 > 编程问答 >

Extracting substring from txt file JAVA

问题描述:

I am trying to extract substrings from a text file that I have using java. For instance, I would like to extract from the 112th (number right after the # sign) letter to the 145th (second number after the # sign) character of the string SKEPLRCRPINATL......

DisProt|DP00013|uniprot|P01233|unigene|Hs.172944|sp|CGHB_HUMAN #112-145 SKEPLRPRCRPINATLAVEKEGCPVCITVNTTICAGYCPTMTRVLQGVLPALPQVVCNYRDVRFESIRLPGCPRGVNPVVSYAVALSCQCALCRRSTTDCGGPKDHPLTCDDPRFQDSSSSKAPPPSLPSPSRLPGPSDTPILPQ

Would anyone please tell me how to go about this?

Thanks a bunch in advance!

网友答案:

Would anyone please tell me how to go about this?

Yes but no code... Javadoc links below.

  • Find last index of # in the first line.
  • Split with "-"; convert each part to integers.
  • Open a buffered reader on the file (that is Files.newBufferedReader(); use Paths.get() to get the Path).
  • Loop over each line, extract substring from beginning index to ending index.

All methods to do this are available in the String class (except for the integer conversion: class Integer).

分享给朋友:
您可能感兴趣的文章:
随机阅读: