View Single Post
Old 03-15-2011, 07:48 PM   PM User | #4
Aradon
Moderator-san


 
Aradon's Avatar
 
Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Aradon is on a distinguished road
Can you give us an example of when it doesn't work?

Here is the code I wrote and it's outputs:

Code:
import java.util.*;

public class testCodingforums {

	public static void main (String args[])
	{
		String fileName = "01 - infected mushroom - cities of the future - radio edit.txt";

        StringTokenizer tokens = new StringTokenizer(fileName);

        boolean firstDashFound = false;
        boolean secondDashFound = false;
        String songTitle = "";
        String artist = "";

        while(tokens.hasMoreElements()){
            String aWord = tokens.nextToken();
            if(firstDashFound && !secondDashFound && !aWord.equals("-"))
                artist = artist + aWord + " ";
            if(secondDashFound) songTitle = songTitle + aWord + " ";
            if(aWord.equals("-")){
                if(firstDashFound) secondDashFound = true;
                firstDashFound = true;
            }
        }
        String newSongTitle = "";
        boolean dotFound = false;
        for(int i = 0; i < songTitle.length(); i++){
            if(songTitle.charAt(i) == '.') dotFound = true;
            if(!dotFound) newSongTitle = newSongTitle + songTitle.charAt(i);
        }
        String newArtistName = artist.trim();
        
        System.out.println(newArtistName);
        System.out.println(newSongTitle);
	}
}
Code:
Outputs: 

infected mushroom
cities of the future - radio edit
So it looks like your looping is pretty sound given the input you've given us. Maybe your outputting is wrong?
__________________
"To iterate is human, to recurse divine." -L. Peter Deutsch
Aradon is offline   Reply With Quote