G
gajo
Hi!
I'm interested if there is a simple way of doing the following: I have a
structure of data, let's say String A, String B and String C. The user can
fill out all three with some data, but he doesn't have to, so in that case
that string will remain empty (""). Now after the user clicks on "Save", the
data is saved to a file, delimited by a string of signs, let's say *#$. So,
a usual line would look like this:
tree*#$mountain*#$apple A=tree, B=mountain, C=apple
lion*#$*#$monkey A=lion, B="", C=monkey
*#$*#$*#$ A = B = C = ""
Then I try to read this back from the file, and using the StringTokenizer I
split a line into tokens. The trouble is that the StringTokenizer doesn't
read the empty strings, but instead jumps over them, so for example where I
had lion*#$*#$monkey A=lion, B="", C=monkey, after reading it back I will
get A=lion, B=monkey, C=<an exception will occur, no more tokens>.
Is there a way for me to do it in a simple way that the StringTokenizer does
read the empty strings? I could of course split the string with
StringTokenizer(someString, true), but then I have to check if a token is *,
# or $, or something else, how many lines do I have to read more, is it the
end of the line etc. or in other words I wouldn't have to use the
StringTokenizer at all!
Gajo
I'm interested if there is a simple way of doing the following: I have a
structure of data, let's say String A, String B and String C. The user can
fill out all three with some data, but he doesn't have to, so in that case
that string will remain empty (""). Now after the user clicks on "Save", the
data is saved to a file, delimited by a string of signs, let's say *#$. So,
a usual line would look like this:
tree*#$mountain*#$apple A=tree, B=mountain, C=apple
lion*#$*#$monkey A=lion, B="", C=monkey
*#$*#$*#$ A = B = C = ""
Then I try to read this back from the file, and using the StringTokenizer I
split a line into tokens. The trouble is that the StringTokenizer doesn't
read the empty strings, but instead jumps over them, so for example where I
had lion*#$*#$monkey A=lion, B="", C=monkey, after reading it back I will
get A=lion, B=monkey, C=<an exception will occur, no more tokens>.
Is there a way for me to do it in a simple way that the StringTokenizer does
read the empty strings? I could of course split the string with
StringTokenizer(someString, true), but then I have to check if a token is *,
# or $, or something else, how many lines do I have to read more, is it the
end of the line etc. or in other words I wouldn't have to use the
StringTokenizer at all!
Gajo