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
    • 541
    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

     

    1. public class Reversewhileloop {
    2.  
    3. /** * @param args the command line arguments *
    4.  
    5. @throws java.io.FileNotFoundException */
    6.  
    7. public static void main(String[] args) throws FileNotFoundException, IOException {
    8.  
    9. try { BufferedReader in = new BufferedReader(new FileReader(new File("Untitled Document 1.txt")));
    10.  
    11. System.out.println("File open successful!");
    12.  
    13. int line = 0;
    14.  
    15. String[] tempArray;
    16.  
    17. for (String x = in.readLine(); x != null; x = in.readLine()) {
    18.  
    19. line++;
    20.  
    21. String[] tokens = x.split("=");
    22.  
    23. for (int i = 0; i < tokens.length; i++)
    24.  
    25. { System.out.println("Str[" + i + "]:" + tokens[i]); }
    26.  
    27. }
    28.  
    29. } catch (IOException e) {
    30.  
    31. System.out.println("File I/O error!"); }
    32.  
    33. }
    34.  
    35. }

     

    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
Reset Password
Fill out the form below and reset your password: