Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Split String From a Javascript File into Two Array String

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 431
    Answer it

    I want split string from file into two array string......

     

    file contain this-

     

    • Bangladesh= 109.408
    • India= 92.7478
    • Pakistan= 200.550
    • USA= 1.29221
    • Europe= 1.16989
    • UK= 1
    • SA= 4.85180
    • Australia= 1.90035
    • Canada= 1.71097

     

    public class Reversewhileloop {
    
    /** * @param args the command line arguments *
    
    @throws java.io.FileNotFoundException */
    
    public static void main(String[] args) throws FileNotFoundException, IOException {
    
    try { BufferedReader in = new BufferedReader(new FileReader(new File("Untitled Document 1.txt")));
    
    System.out.println("File open successful!");
    
    int line = 0;
    
    String[] tempArray;
    
    for (String x = in.readLine(); x != null; x = in.readLine()) {
    
    line++;
    
    String[] tokens = x.split("=");
    
    for (int i = 0; i < tokens.length; i++)
    
    { System.out.println("Str[" + i + "]:" + tokens[i]); }
    
    }
    
    } catch (IOException e) {
    
    System.out.println("File I/O error!"); }
    
    }
    
    }

     

    Output is-

    Str[0]:Bangladesh

    Str[1]: 109.408

    Str[0]:India

    Str[1]: 92.7478

    Str[0]:Pakistan

    Str[1]: 200.550

    Str[0]:USA

    Str[1]: 1.29221

     

    but I want output like this way-

    Str[1]:Bangladesh

    Str[2]: 109.408

    Str[3]:India

    Str[4]: 92.7478

    Str[5]:Pakistan

    Str[6]: 200.550

    Str[7]:USA

    Str[8]: 1.29221

     

    OR

    Str[1]:Bangladesh

    Str[2]:India

    Str[3]:Pakistan

    Str[4]:USA

    Str1[1]:109.408

    Str1[2]: 92.7478

    Str1[3]: 200.550

    Str1[4]: 1.29221

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: