Java:如何从字符串中删除第三个单词?

时间:2014-09-05 09:02:38

标签: java

我想挑出输入字符串的第三个字并将其保存到新变量中。有关我可以使用的方法的任何指针吗?

大多数人都想要更多信息,因此该程序用于切割产品标题并分发关键字以填写我编写的html元数据块的空白。标题中的第一个字始终是模型的制造商,第二个是汽车的制造商,第三个是汽车的制造商。我已经为所有汽车和模型制造商编写了代码,使用.contains方法,但是汽车制造的版本太多而且广泛,让我只需要从标题中删除字词并将其直接保存到变量中。我能给你的唯一代码是我到目前为止在程序中所拥有的代码,因为我甚至不知道从哪里开始切割输入的字符串。

这是我到目前为止所做的:

import java.util.Scanner; 公共课MetagenV3 {

private static boolean keepRunning;

public static void main (String[] args) {

    do {
    GenerateData(); }
    while (keepRunning = true);
    if (keepRunning = false) {
        System.exit(0);
    }
}

    public static void GenerateData() {

    Scanner sc = new Scanner(System.in);
    String title = null;
    String abstr = "Shop for diecast model cars at [SITE REMOVED]";
    String scale = null;
    String diecastManu = null;
    String metaModel = null;
    String metaMake = null;
    String defaultstring = "quality";

    String[] metaMakesList = {"Abarth", "Acura", "Ahrens", "Alfa Romeo"
            +"Alpine Renault", "AMC", "American LaFrance", "Aprilia", "Aston Martin" 
            +"Audi", "Austin", "Austin-Healey", "Bedford", "Benelli", "Bentley", "BMW"
            +"Buffalo", "Bugatti", "Buick","Cadillac","Caterham", "Chaparrel"
            + "Checker","Chevrolet","Chrysler","Citroen", "Cleveland", "Cord","DAF"
            + "Daimler","Dakota","Datsun","Dauer","De Soto", "Delahaye", "DeLorean", "Dennis", "Divco"
            + "Dodge", "Duesenberg", "Edsel", "F1", "Ferrari","Fiat","Ford","Freightliner"
            +"GAZ", "GMC", "Gumpert", "Halo", "Helicopter","Hello Kitty", "Honda","Horch","Hudson"
            + "Hummer","Hyundai","Infiniti", "International", "Jaguar", "Jeep", "K2", "Kaiser"
            + "Koenigsegg","Lamborghini","Lancia","Land Rover", "LandRover", "Lexus","Leyland"
            + "Lincoln", "Lotus","Mack","Magirus-Deutz","Maserati","Maxim", "Maybach"
            + "Mazda","McLaren","Mercedes-Benz","Mercedes Benz","Mercedes","Mercury","Messerschmitt"
            +"Meyers Manxter","MG","Mini","Mini Cooper","Mitsubishi","Morgan","Morris"
            + "Nash", "Nissan","Oldsmobile","Opel","Packard","Pagani","Panhard","Panoz","Pantera"
            + "Peugeot","Pierce-Arrow","Plymouth","Pontiac","Porsche","Puegoet","Renault","Reo"
            + "Rolls Royce", "Rolls-Royce","Saturn","Scion","Seagrave","Seat","Simca", "Smart"
            + "Studebaker","Stutz", "Subaru","Tata","Toyota","Triumph","Tucker","TVR","TX1"
            + "VolksWagen","Volvo","White","Willys"};

    String[] scaleList = {"1:12","1:18","1:24","1:32","1:43","1:64","1/12", "1/18", "1/24", "1/32", "1/43", "1/64"};

    String[] diecastManuList = {"Muscle Machines","Jada Toys"
                    +"AUTOart","Kinsmart","M2","1BaddRide"
                    +"Greenlight","Anson","Arko","Auto World"
                    +"Bauer","BBR","BBurago","Carney Plastics"
                    +"Collectable Diecast","CMC","Double Horse"
                    +"Elvis Motor Classics","Classic Metal Works"
                    +"Ertl","Fast Women","First Gear","GMP","Hawk"
                    +"Highway 61","Hot Wheels","Hot Works","IXO"
                    +"Johnny Lightning","Kustom City","Kyosho"
                    +"LandMice","Lane Exact Detail","Liberty Classics"
                    +"LJP","Luxury","Lindberg","Maisto","Minichamps"
                    +"Mira-Solido","MJX","Mondo Motors","Motor City"
                    +"Motorhead","Motormax","New Ray","Norev"
                    +"Paragon","Paudi","Pioneer","Phoenix Mint"
                    +"Precision Miniatures","Revell","Ricko Ricko"
                    +"RMZ City","Road Mice","Saico","Schuco","Shelby Collectibles"
                    +"Signature","So Real Concepts","SpecCast"
                    +"SunStar","Superior","Syma","True Scale"
                    +"Unique Replicas","Universal Hobbies"
                    +"Vitesse","XQ","Yat-Ming","Welly"};

    //System.out.println(diecastManuList.length);
    System.out.println("Please paste model title.");
    title = sc.nextLine();

    if (title.toLowerCase().contains(metaMakesList[0].toLowerCase()))
    { metaMake = metaMakesList[0];}
    else if (title.toLowerCase().contains(metaMakesList[1].toLowerCase()))
    { metaMake = metaMakesList[1];}
    else if (title.toLowerCase().contains(metaMakesList[2].toLowerCase()))
    { metaMake = metaMakesList[2];}
    else if (title.toLowerCase().contains(metaMakesList[3].toLowerCase()))
    { metaMake = metaMakesList[3];}
    else if (title.toLowerCase().contains(metaMakesList[4].toLowerCase()))
    { metaMake = metaMakesList[4];}
    else if (title.toLowerCase().contains(metaMakesList[5].toLowerCase()))
    { metaMake = metaMakesList[5];}
    else if (title.toLowerCase().contains(metaMakesList[6].toLowerCase()))
    { metaMake = metaMakesList[6];}
    else if (title.toLowerCase().contains(metaMakesList[7].toLowerCase()))
    { metaMake = metaMakesList[7];}
    else if (title.toLowerCase().contains(metaMakesList[8].toLowerCase()))
    { metaMake = metaMakesList[8];}
    else if (title.toLowerCase().contains(metaMakesList[9].toLowerCase()))
    { metaMake = metaMakesList[9];}
    else if (title.toLowerCase().contains(metaMakesList[10].toLowerCase()))
    { metaMake = metaMakesList[10];}
    else if (title.toLowerCase().contains(metaMakesList[11].toLowerCase()))
    { metaMake = metaMakesList[11];}
    else if (title.toLowerCase().contains(metaMakesList[12].toLowerCase()))
    { metaMake = metaMakesList[12];}
    else if (title.toLowerCase().contains(metaMakesList[13].toLowerCase()))
    { metaMake = metaMakesList[13];}
    else if (title.toLowerCase().contains(metaMakesList[14].toLowerCase()))
    { metaMake = metaMakesList[14];}
    else if (title.toLowerCase().contains(metaMakesList[15].toLowerCase()))
    { metaMake = metaMakesList[15];}
    else if (title.toLowerCase().contains(metaMakesList[16].toLowerCase()))
    { metaMake = metaMakesList[16];}
    else if (title.toLowerCase().contains(metaMakesList[17].toLowerCase()))
    { metaMake = metaMakesList[17];}
    else if (title.toLowerCase().contains(metaMakesList[18].toLowerCase()))
    { metaMake = metaMakesList[18];}
    else if (title.toLowerCase().contains(metaMakesList[19].toLowerCase()))
    { metaMake = metaMakesList[19];}
    else if (title.toLowerCase().contains(metaMakesList[20].toLowerCase()))
    { metaMake = metaMakesList[20];}
    else if (title.toLowerCase().contains(metaMakesList[21].toLowerCase()))
    { metaMake = metaMakesList[21];}
    else if (title.toLowerCase().contains(metaMakesList[22].toLowerCase()))
    { metaMake = metaMakesList[22];}
    else if (title.toLowerCase().contains(metaMakesList[23].toLowerCase()))
    { metaMake = metaMakesList[23];}
    else if (title.toLowerCase().contains(metaMakesList[24].toLowerCase()))
    { metaMake = metaMakesList[24];}
    else if (title.toLowerCase().contains(metaMakesList[25].toLowerCase()))
    { metaMake = metaMakesList[25];}
    else if (title.toLowerCase().contains(metaMakesList[26].toLowerCase()))
    { metaMake = metaMakesList[26];}
    else if (title.toLowerCase().contains(metaMakesList[27].toLowerCase()))
    { metaMake = metaMakesList[27];}
    else if (title.toLowerCase().contains(metaMakesList[28].toLowerCase()))
    { metaMake = metaMakesList[28];}
    else if (title.toLowerCase().contains(metaMakesList[29].toLowerCase()))
    { metaMake = metaMakesList[29];}
    else if (title.toLowerCase().contains(metaMakesList[30].toLowerCase()))
    { metaMake = metaMakesList[30];}
    else if (title.toLowerCase().contains(metaMakesList[31].toLowerCase()))
    { metaMake = metaMakesList[31];}
    else if (title.toLowerCase().contains(metaMakesList[32].toLowerCase()))
    { metaMake = metaMakesList[32];}
    else if (title.toLowerCase().contains(metaMakesList[33].toLowerCase()))
    { metaMake = metaMakesList[33];}
    else if (title.toLowerCase().contains(metaMakesList[34].toLowerCase()))
    { metaMake = metaMakesList[34];}
    else if (title.toLowerCase().contains(metaMakesList[35].toLowerCase()))
    { metaMake = metaMakesList[35];}
    else if (title.toLowerCase().contains(metaMakesList[36].toLowerCase()))
    { metaMake = metaMakesList[36];}
    else if (title.toLowerCase().contains(metaMakesList[37].toLowerCase()))
    { metaMake = metaMakesList[37];}
    else if (title.toLowerCase().contains(metaMakesList[38].toLowerCase()))
    { metaMake = metaMakesList[38];}
    else if (title.toLowerCase().contains(metaMakesList[39].toLowerCase()))
    { metaMake = metaMakesList[39];}
    else if (title.toLowerCase().contains(metaMakesList[40].toLowerCase()))
    { metaMake = metaMakesList[40];}
    else if (title.toLowerCase().contains(metaMakesList[41].toLowerCase()))
    { metaMake = metaMakesList[41];}
    else if (title.toLowerCase().contains(metaMakesList[42].toLowerCase()))
    { metaMake = metaMakesList[42];}
    else if (title.toLowerCase().contains(metaMakesList[43].toLowerCase()))
    { metaMake = metaMakesList[43];}
    else if (title.toLowerCase().contains(metaMakesList[44].toLowerCase()))
    { metaMake = metaMakesList[44];}
    else if (title.toLowerCase().contains(metaMakesList[45].toLowerCase()))
    { metaMake = metaMakesList[45];}
    else if (title.toLowerCase().contains(metaMakesList[46].toLowerCase()))
    { metaMake = metaMakesList[46];}
    else if (title.toLowerCase().contains(metaMakesList[47].toLowerCase()))
    { metaMake = metaMakesList[47];}
    else if (title.toLowerCase().contains(metaMakesList[48].toLowerCase()))
    { metaMake = metaMakesList[48];}
    else if (title.toLowerCase().contains(metaMakesList[49].toLowerCase()))
    { metaMake = metaMakesList[49];}
    else if (title.toLowerCase().contains(metaMakesList[50].toLowerCase()))
    { metaMake = metaMakesList[50];}
    else if (title.toLowerCase().contains(metaMakesList[51].toLowerCase()))
    { metaMake = metaMakesList[51];}
    else if (title.toLowerCase().contains(metaMakesList[52].toLowerCase()))
    { metaMake = metaMakesList[52];}
    else if (title.toLowerCase().contains(metaMakesList[53].toLowerCase()))
    { metaMake = metaMakesList[53];}
    else if (title.toLowerCase().contains(metaMakesList[54].toLowerCase()))
    { metaMake = metaMakesList[54];}
    else if (title.toLowerCase().contains(metaMakesList[55].toLowerCase()))
    { metaMake = metaMakesList[55];}
    else if (title.toLowerCase().contains(metaMakesList[56].toLowerCase()))
    { metaMake = metaMakesList[56];}
    else if (title.toLowerCase().contains(metaMakesList[57].toLowerCase()))
    { metaMake = metaMakesList[57];}
    else if (title.toLowerCase().contains(metaMakesList[58].toLowerCase()))
    { metaMake = metaMakesList[58];}
    else if (title.toLowerCase().contains(metaMakesList[59].toLowerCase()))
    { metaMake = metaMakesList[59];}
    else if (title.toLowerCase().contains(metaMakesList[60].toLowerCase()))
    { metaMake = metaMakesList[60];}
    else if (title.toLowerCase().contains(metaMakesList[61].toLowerCase()))
    { metaMake = metaMakesList[61];}
    else if (title.toLowerCase().contains(metaMakesList[62].toLowerCase()))
    { metaMake = metaMakesList[62];}
    else if (title.toLowerCase().contains(metaMakesList[63].toLowerCase()))
    { metaMake = metaMakesList[63];}
    else if (title.toLowerCase().contains(metaMakesList[64].toLowerCase()))
    { metaMake = metaMakesList[64];}
    else if (title.toLowerCase().contains(metaMakesList[65].toLowerCase()))
    { metaMake = metaMakesList[65];}
    else if (title.toLowerCase().contains(metaMakesList[66].toLowerCase()))
    { metaMake = metaMakesList[66];}
    else if (title.toLowerCase().contains(metaMakesList[67].toLowerCase()))
    { metaMake = metaMakesList[67];}
    else if (title.toLowerCase().contains(metaMakesList[68].toLowerCase()))
    { metaMake = metaMakesList[68];}
    else if (title.toLowerCase().contains(metaMakesList[69].toLowerCase()))
    { metaMake = metaMakesList[69];}
    else if (title.toLowerCase().contains(metaMakesList[70].toLowerCase()))
    { metaMake = metaMakesList[70];}
    else if (title.toLowerCase().contains(metaMakesList[71].toLowerCase()))
    { metaMake = metaMakesList[71];}
    else if (title.toLowerCase().contains(metaMakesList[72].toLowerCase()))
    { metaMake = metaMakesList[72];}
    else if (title.toLowerCase().contains(metaMakesList[73].toLowerCase()))
    { metaMake = metaMakesList[73];}
    else if (title.toLowerCase().contains(metaMakesList[74].toLowerCase()))
    { metaMake = metaMakesList[74];}
    else if (title.toLowerCase().contains(metaMakesList[75].toLowerCase()))
    { metaMake = metaMakesList[75];}
    else if (title.toLowerCase().contains(metaMakesList[76].toLowerCase()))
    { metaMake = metaMakesList[76];}
    else if (title.toLowerCase().contains(metaMakesList[77].toLowerCase()))
    { metaMake = metaMakesList[77];}
    else if (title.toLowerCase().contains(metaMakesList[78].toLowerCase()))
    { metaMake = metaMakesList[78];}
    else if (title.toLowerCase().contains(metaMakesList[79].toLowerCase()))
    { metaMake = metaMakesList[79];}
    else if (title.toLowerCase().contains(metaMakesList[80].toLowerCase()))
    { metaMake = metaMakesList[80];}
    else if (title.toLowerCase().contains(metaMakesList[81].toLowerCase()))
    { metaMake = metaMakesList[81];}
    else if (title.toLowerCase().contains(metaMakesList[82].toLowerCase()))
    { metaMake = metaMakesList[82];}
    else if (title.toLowerCase().contains(metaMakesList[83].toLowerCase()))
    { metaMake = metaMakesList[83];}
    else if (title.toLowerCase().contains(metaMakesList[84].toLowerCase()))
    { metaMake = metaMakesList[84];}
    else if (title.toLowerCase().contains(metaMakesList[85].toLowerCase()))
    { metaMake = metaMakesList[85];}
    else if (title.toLowerCase().contains(metaMakesList[86].toLowerCase()))
    { metaMake = metaMakesList[86];}
    else if (title.toLowerCase().contains(metaMakesList[87].toLowerCase()))
    { metaMake = metaMakesList[87];}
    else if (title.toLowerCase().contains(metaMakesList[88].toLowerCase()))
    { metaMake = metaMakesList[88];}
    else if (title.toLowerCase().contains(metaMakesList[89].toLowerCase()))
    { metaMake = metaMakesList[89];}
    else if (title.toLowerCase().contains(metaMakesList[90].toLowerCase()))
    { metaMake = metaMakesList[90];}
    else if (title.toLowerCase().contains(metaMakesList[91].toLowerCase()))
    { metaMake = metaMakesList[91];}
    else if (title.toLowerCase().contains(metaMakesList[92].toLowerCase()))
    { metaMake = metaMakesList[92];}
    else if (title.toLowerCase().contains(metaMakesList[93].toLowerCase()))
    { metaMake = metaMakesList[93];}
    else if (title.toLowerCase().contains(metaMakesList[94].toLowerCase()))
    { metaMake = metaMakesList[94];}
    else if (title.toLowerCase().contains(metaMakesList[95].toLowerCase()))
    { metaMake = metaMakesList[95];}
    else if (title.toLowerCase().contains(metaMakesList[96].toLowerCase()))
    { metaMake = metaMakesList[96];}
    else if (title.toLowerCase().contains(metaMakesList[97].toLowerCase()))
    { metaMake = metaMakesList[97];}
    else if (title.toLowerCase().contains(metaMakesList[98].toLowerCase()))
    { metaMake = metaMakesList[98];}
    else if (title.toLowerCase().contains(metaMakesList[99].toLowerCase()))
    { metaMake = metaMakesList[99];}
    else if (title.toLowerCase().contains(metaMakesList[100].toLowerCase()))
    { metaMake = metaMakesList[100];}
    else if (title.toLowerCase().contains(metaMakesList[101].toLowerCase()))
    { metaMake = metaMakesList[101];}
    else if (title.toLowerCase().contains(metaMakesList[102].toLowerCase()))
    { metaMake = metaMakesList[102];}
    else if (title.toLowerCase().contains(metaMakesList[103].toLowerCase()))
    { metaMake = metaMakesList[103];}
    else if (title.toLowerCase().contains(metaMakesList[104].toLowerCase()))
    { metaMake = metaMakesList[104];}
    else if (title.toLowerCase().contains(metaMakesList[105].toLowerCase()))
    { metaMake = metaMakesList[105];}
    else if (title.toLowerCase().contains(metaMakesList[106].toLowerCase()))
    { metaMake = metaMakesList[106];}
    else if (title.toLowerCase().contains(metaMakesList[107].toLowerCase()))
    { metaMake = metaMakesList[107];}
    else if (title.toLowerCase().contains(metaMakesList[108].toLowerCase()))
    { metaMake = metaMakesList[108];}
    else if (title.toLowerCase().contains(metaMakesList[109].toLowerCase()))
    { metaMake = metaMakesList[109];}
    else if (title.toLowerCase().contains(metaMakesList[110].toLowerCase()))
    { metaMake = metaMakesList[110];}
    else if (title.toLowerCase().contains(metaMakesList[111].toLowerCase()))
    { metaMake = metaMakesList[111];}
    else {
        metaMake = defaultstring;
    }

    if (title.toLowerCase().contains(scaleList[0].toLowerCase()))
    { scale = scaleList[0]; }
    else if (title.toLowerCase().contains(scaleList[1].toLowerCase()))
    { scale = scaleList[1]; }
    else if (title.toLowerCase().contains(scaleList[2].toLowerCase()))
    { scale = scaleList[2]; }
    else if (title.toLowerCase().contains(scaleList[3].toLowerCase()))
    { scale = scaleList[3]; }
    else if (title.toLowerCase().contains(scaleList[4].toLowerCase()))
    { scale = scaleList[4]; }
    else if (title.toLowerCase().contains(scaleList[5].toLowerCase()))
    { scale = scaleList[5]; }
    else if (title.toLowerCase().contains(scaleList[6].toLowerCase()))
    { scale = scaleList[6]; }
    else if (title.toLowerCase().contains(scaleList[7].toLowerCase()))
    { scale = scaleList[7]; }
    else if (title.toLowerCase().contains(scaleList[8].toLowerCase()))
    { scale = scaleList[8]; }
    else if (title.toLowerCase().contains(scaleList[9].toLowerCase()))
    { scale = scaleList[9]; }
    else if (title.toLowerCase().contains(scaleList[10].toLowerCase()))
    { scale = scaleList[10]; }
    else if (title.toLowerCase().contains(scaleList[11].toLowerCase()))
    { scale = scaleList[11]; }

    else { scale = defaultstring;}

    if (title.toLowerCase().contains(diecastManuList[0].toLowerCase()))
    { diecastManu = diecastManuList[0]; }
    else if (title.toLowerCase().contains(diecastManuList[1].toLowerCase()))
    { diecastManu = diecastManuList[1]; }
    else if (title.toLowerCase().contains(diecastManuList[2].toLowerCase()))
    { diecastManu = diecastManuList[2]; }
    else if (title.toLowerCase().contains(diecastManuList[3].toLowerCase()))
    { diecastManu = diecastManuList[3]; }
    else if (title.toLowerCase().contains(diecastManuList[4].toLowerCase()))
    { diecastManu = diecastManuList[4]; }
    else if (title.toLowerCase().contains(diecastManuList[5].toLowerCase()))
    { diecastManu = diecastManuList[5]; }
    else if (title.toLowerCase().contains(diecastManuList[6].toLowerCase()))
    { diecastManu = diecastManuList[6]; }
    else if (title.toLowerCase().contains(diecastManuList[7].toLowerCase()))
    { diecastManu = diecastManuList[7]; }
    else if (title.toLowerCase().contains(diecastManuList[8].toLowerCase()))
    { diecastManu = diecastManuList[8]; }
    else if (title.toLowerCase().contains(diecastManuList[9].toLowerCase()))
    { diecastManu = diecastManuList[9]; }
    else if (title.toLowerCase().contains(diecastManuList[10].toLowerCase()))
    { diecastManu = diecastManuList[10]; }
    else if (title.toLowerCase().contains(diecastManuList[11].toLowerCase()))
    { diecastManu = diecastManuList[11]; }
    else if (title.toLowerCase().contains(diecastManuList[12].toLowerCase()))
    { diecastManu = diecastManuList[12]; }
    else if (title.toLowerCase().contains(diecastManuList[13].toLowerCase()))
    { diecastManu = diecastManuList[13]; }
    else if (title.toLowerCase().contains(diecastManuList[14].toLowerCase()))
    { diecastManu = diecastManuList[14]; }
    else if (title.toLowerCase().contains(diecastManuList[15].toLowerCase()))
    { diecastManu = diecastManuList[15]; }
    else if (title.toLowerCase().contains(diecastManuList[16].toLowerCase()))
    { diecastManu = diecastManuList[16]; }
    else if (title.toLowerCase().contains(diecastManuList[17].toLowerCase()))
    { diecastManu = diecastManuList[17]; }
    else if (title.toLowerCase().contains(diecastManuList[18].toLowerCase()))
    { diecastManu = diecastManuList[18]; }
    else if (title.toLowerCase().contains(diecastManuList[19].toLowerCase()))
    { diecastManu = diecastManuList[19]; }
    else if (title.toLowerCase().contains(diecastManuList[20].toLowerCase()))
    { diecastManu = diecastManuList[20]; }
    else if (title.toLowerCase().contains(diecastManuList[21].toLowerCase()))
    { diecastManu = diecastManuList[21]; }
    else if (title.toLowerCase().contains(diecastManuList[22].toLowerCase()))
    { diecastManu = diecastManuList[22]; }
    else if (title.toLowerCase().contains(diecastManuList[23].toLowerCase()))
    { diecastManu = diecastManuList[23]; }
    else if (title.toLowerCase().contains(diecastManuList[24].toLowerCase()))
    { diecastManu = diecastManuList[24]; }
    else if (title.toLowerCase().contains(diecastManuList[25].toLowerCase()))
    { diecastManu = diecastManuList[25]; }
    else if (title.toLowerCase().contains(diecastManuList[26].toLowerCase()))
    { diecastManu = diecastManuList[26]; }
    else if (title.toLowerCase().contains(diecastManuList[27].toLowerCase()))
    { diecastManu = diecastManuList[27]; }
    else if (title.toLowerCase().contains(diecastManuList[28].toLowerCase()))
    { diecastManu = diecastManuList[28]; }
    else if (title.toLowerCase().contains(diecastManuList[29].toLowerCase()))
    { diecastManu = diecastManuList[29]; }
    else if (title.toLowerCase().contains(diecastManuList[30].toLowerCase()))
    { diecastManu = diecastManuList[30]; }
    else if (title.toLowerCase().contains(diecastManuList[31].toLowerCase()))
    { diecastManu = diecastManuList[31]; }
    else if (title.toLowerCase().contains(diecastManuList[32].toLowerCase()))
    { diecastManu = diecastManuList[32]; }
    else if (title.toLowerCase().contains(diecastManuList[33].toLowerCase()))
    { diecastManu = diecastManuList[33]; }
    else if (title.toLowerCase().contains(diecastManuList[34].toLowerCase()))
    { diecastManu = diecastManuList[34]; }
    else if (title.toLowerCase().contains(diecastManuList[35].toLowerCase()))
    { diecastManu = diecastManuList[35]; }
    else if (title.toLowerCase().contains(diecastManuList[36].toLowerCase()))
    { diecastManu = diecastManuList[36]; }
    else if (title.toLowerCase().contains(diecastManuList[37].toLowerCase()))
    { diecastManu = diecastManuList[37]; }
    else if (title.toLowerCase().contains(diecastManuList[38].toLowerCase()))
    { diecastManu = diecastManuList[38]; }
    else if (title.toLowerCase().contains(diecastManuList[39].toLowerCase()))
    { diecastManu = diecastManuList[39]; }
    else if (title.toLowerCase().contains(diecastManuList[40].toLowerCase()))
    { diecastManu = diecastManuList[40]; }
    else if (title.toLowerCase().contains(diecastManuList[41].toLowerCase()))
    { diecastManu = diecastManuList[41]; }
    else if (title.toLowerCase().contains(diecastManuList[42].toLowerCase()))
    { diecastManu = diecastManuList[42]; }
    else if (title.toLowerCase().contains(diecastManuList[43].toLowerCase()))
    { diecastManu = diecastManuList[43]; }
    else if (title.toLowerCase().contains(diecastManuList[44].toLowerCase()))
    { diecastManu = diecastManuList[44]; }
    else if (title.toLowerCase().contains(diecastManuList[45].toLowerCase()))
    { diecastManu = diecastManuList[45]; }
    else if (title.toLowerCase().contains(diecastManuList[46].toLowerCase()))
    { diecastManu = diecastManuList[46]; }
    else if (title.toLowerCase().contains(diecastManuList[47].toLowerCase()))
    { diecastManu = diecastManuList[47]; }
    else if (title.toLowerCase().contains(diecastManuList[48].toLowerCase()))
    { diecastManu = diecastManuList[48]; }
    else if (title.toLowerCase().contains(diecastManuList[49].toLowerCase()))
    { diecastManu = diecastManuList[49]; }
    else if (title.toLowerCase().contains(diecastManuList[50].toLowerCase()))
    { diecastManu = diecastManuList[50]; }
    else if (title.toLowerCase().contains(diecastManuList[51].toLowerCase()))
    { diecastManu = diecastManuList[51]; }
    else if (title.toLowerCase().contains(diecastManuList[52].toLowerCase()))
    { diecastManu = diecastManuList[52]; }
    else {
        diecastManu = defaultstring;
    }



    System.out.println("Please paste car model (e.g Skyline).");
    metaModel = sc.nextLine();


String fullOutput = "<METANAME="  + "\"DESCRIPTION\"" + "CONTENT=\"" + "Shop for " + title + " "
        + "diecast model cars at [SITE REMOVED]\"" +">" + "\n"
            + "<METANAME="  + "\"ABSTRACT\"" + "CONTENT=" + abstr + "\n"
         +  "<METANAME="  + "\"KEYWORDS\"" + "CONTENT=" + "“diecast cars, diecast " + scale + " "
                + "scale cars," + "\n" + "diecast model cars, modelcars, collectable cars, "
         + diecastManu + " diecast"
                        + " model, " + metaMake + " diecast cars, diecast " + metaModel +"\">";

System.out.println(fullOutput);

System.out.println("Press 'y' to run again.");
String asker = sc.next();
if (asker.equalsIgnoreCase("y"))
{ keepRunning = true;}
else { keepRunning = false;}
}

}

我希望能够排除这一行:

         System.out.println("Please paste car model (e.g Skyline).");
            metaModel = sc.nextLine();

并自动填写。

2 个答案:

答案 0 :(得分:1)

只是为了开始,代码不是最佳

public class Main {
    public static void main(String[] args) {
        String s1 = "StackOverflow wants you to show efforts";
        String[] s2 = s1.split(" ");
        System.out.println(s2[2]);
    }
}

答案 1 :(得分:0)

请尝试以下操作:

String input="First Second Third";
String tok[]=input.split(" ");
input="";
for(int i=0;i<tok.length;i++)
{
 if(i!=2)
  {
   input=input+tok[i]+" ";
  }
}
System.out.println(input.trim());

<强>输出:

First Second

注意:诀窍是将每个单词从输入文本中分离出来并获得第三个单词。对于冗长的输入,请使用StringBuilder代替String