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?
3 Antworten
+ 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
+ 4
str.split(":")[x]
just switch x with 0 or 1 or better yet, do it in a loop
0
i need to display the 1st two things as well