I need a little help.
I have a matrix which has 25 rows and 4 columns (it's defined "MiaSquadra[25][4]").
What I wanna do is to transfer the datas from this matrix to an empty exisiting file called "juventus.txt".
But the writing must be personalized, in fact I would like to write 25 rows (corresponding to the rows of the matrix) and each rows should be composed by the datas from the 4 columns with a symbol "%" as delimitator.
Example:
MiaSquadra[1][1] = Christian Buffon
MiaSquadra[1][2] = P
MiaSquadra[1][3] = Juventus
MiaSquadra[1][4] = 23
so I should open the file "juventus.txt" (which is empty) and write the first row that must appears like follow:
Christian Buffon%P%Juventus%23
and so on for the remaining rows till 25.
I tried in different ways to do this but I failed :(
I am new in Java and maybe I wrong just some small thing :rolleyes:
Can someone suggest me the code?
Thanks in advanced!!!!
Bye miriam
09-26-2002, 10:26 AM
Pankaj
hi,
read documentation for StringTokenizer class - it has an array of methods and variables for convenient string manipulations as you have asked. Here is one sample code:
String s="Christian Buffon%P%Juventus%23");
StringTokenizer st=new StringTokenizer(s,"%");
int num=st.countTokens();
String str[]=new String[num];
int count=0;
while(st.hasMoreElements()){
str[count]=st.nextToken();
count++;
}
bye
09-26-2002, 02:27 PM
mirjam
:) I have read the documentation about StringTokenizer and all its costructors to split lines in tokens... but I didn't solve my problem.
Maybe I didn't understand your suggestion :( but I couldn't apply StringTokenizer class to my problem because I have a matrix and I want to write on a file, that means I have to do an output stream.
The documentation about StringTokenizer class was relating examples of an input stream when you read from file and want to split lines in tokens....
Sorry for my lack of knowledge, probably I didn't catch your advice... can you explain me what I have to do exactly? :confused:
thanks again!
Mirjam