it seems simple and I was confident. I input a tweet string and then parse it out. the first two lines went well and I thought it would just be a repeat.
"#typ fire; #det firefighter sees a glow; #loc sw from west coach rd toward sunshine canyon;
#lat 40.0515; #lng -105.332;"
Type: FIRE
Detail: firefighter sees a glow
Location: sw from west coach rd toward sunshine canyon
Latitude: p fire
Longitude: p fire
should be
Type: FIRE
Detail: firefighter sees a glow
Location: sw from west coach rd toward sunshine canyon
Latitude: 40.0515
Longitude: -105.332
again it seems my first three fields work, and I have used the same logic for the last two fields.
I am guessing it has something to do with the wraping of the text, i.e. it is on two lines?
any help is appreciated
import java.util.Scanner;
public class ParseTheTweet {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Enter a tweet below");
Scanner tweetInput = new Scanner(System.in);
String tweet = tweetInput.nextLine();
tweet = tweet.replace(',','-');
String type, detail, location, latitude, longitude;
int startType = tweet.indexOf("#typ");
int startDetail = tweet.indexOf("#det");
int startLoc = tweet.indexOf("#loc");
int startLat = tweet.indexOf("#lat");
int startLng = tweet.indexOf("#lng");
int finishType = tweet.indexOf(";", startType);
int finishDetail = tweet.indexOf(";", startDetail);
int finishLoc = tweet.indexOf(";", startLoc);
int finishLat = tweet.indexOf(";", startLat);
int finishLng = tweet.indexOf(";", startLng);
//these ten variables mark the start and finish of the index positions needed for the substrings
type = tweet.substring(startType + 5 , finishType);
type = type.toUpperCase();
String typeTrimmed = type.trim();
System.out.print("\nType: \t\t\t");
System.out.println(typeTrimmed);
detail = tweet.substring(startDetail +5, finishDetail);
String detTrimmed = detail.trim();
System.out.print("Detail: \t\t");
System.out.println(detTrimmed);
location = tweet.substring(startLoc + 5, finishLoc);
String locTrimmed = location.trim();
System.out.print("Location: \t\t");
System.out.println(locTrimmed);
latitude = tweet.substring(startLat + 5, finishLat);
String latTrimmed = latitude.trim();
System.out.print("Latitude: \t\t");
System.out.println(latTrimmed);
longitude = tweet.substring(startLng + 5, finishLng);
String lngTrimmed = longitude.trim();
System.out.print("Longitude: \t\t");
System.out.println(lngTrimmed);