This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Is there some sort of a command that will cound the amount of space in between strings? I'm using a tokenizer to extract strings from a line in a file and I want to keep something of a column count, that gives the placement of the string within the line.
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
posted
0
Interesting problem awright. A few ideas... Convert your string to char array and inspect one character at a time. Build up consecutive non-blanks into words, count consecutive blanks or just save the index at the start of each word. Sounds a little finicky. If you have JDK 1.4 or later, look into the Pattern and Match classes and regular expressions. You might be able to put blanks into a group that you can retrieve and inspect. I can't swear that will work. Ask for details if it made no sense. Use tokenizer to get all the words, then use indexOf to get the starting point of each word in the big string. Be careful to use the "from" option in indexOf so you don't confuse words with each other. Do any of those ideas sing to you?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Tom Wolve
Ranch Hand
Joined: Sep 22, 2003
Posts: 32
posted
0
Hi, if you're using a StringTokenizer with ' ' as delimiter character, use it with returnDelims enabled. Count all tokens which are equal to " " and that should do it.
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
posted
0
D'oh! Excellent! I have forgotten that one at some expense before. Shame on me!