简体   繁体   中英

reading specific characters from a text file in java

Before I posted the question, I was searching on the idea, but almost of the answers are not clear for me.

Here is my question: If i have a file contain that contains following string :

45BBHBBBH STREWR GGTEREWEF FRERREWEFFSF FS  W WEERER TWR WR 

How can I read this string character by character ?

I want the first to string be stored in variable on variable and the next in another example:

A = 4 

B = 5 

After that, I want read the rest of string with some logic.

I want to split it into 6 strings and store them in some form data structure

BBHBBB > index 0

BH STR > index 1 ( with the space ) 

and so on

use a char[] to store all the values but instead of A= 4 it would be

yourCharArray[0] =4;

if you want to split the string at the spaces do a loop (str being your string)

while(str.indexOf(" ") != -1)
{
 // substring the code out individually using str.indexOf(" ");
}

hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM