Splitting strings from file | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Splitting strings from file

I need to split these from a file. ale:pass:5 joe:maintain:35 i tried several things already, but it stills displays the same text; ale:pass:5 joe:maintain:35 how can I display it separately?

7th Mar 2017, 7:45 AM
Alejandra Ackers
Alejandra Ackers - avatar
3 Answers
+ 6
use split method on the string with ":" delimiter docs: http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split%28java.lang.String,%20int%29 example: public class Program { public static void main(String[] args) { String str="ale:pass:5"; System.out.println(str.split(":")[2]); } } output: 5
7th Mar 2017, 7:52 AM
Burey
Burey - avatar
+ 4
str.split(":")[x] just switch x with 0 or 1 or better yet, do it in a loop
7th Mar 2017, 3:46 PM
Burey
Burey - avatar
0
i need to display the 1st two things as well
7th Mar 2017, 3:22 PM
Alejandra Ackers
Alejandra Ackers - avatar