Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Replacing File Content

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Replacing File Content

    Hi All,

    I had written a piece of code previosly

    String uniqueFormula = tempFormula[0];
    String[] tempMapVars = tempFormula[1].split("\\s*;\\s*");
    System.out.println(tempMapVars.length);
    	for (int i=0; i< tempMapVars.length; i++){
    		String[] keyValue = tempMapVars[i].split("\\s*=\\s*",2);
    		      if (keyValue.length==2){
    			StringBuffer sb = new StringBuffer(keyValue[0]);
    			sb.append("_").append(runNo++);
    			uniqueFormula = uniqueFormula.replace(keyValue[0],sb.toString());	
    		             var2MeasParaHM.put(new String(sb.toString()), new String(keyValue[1]));
    		      }
                     }

    The content of Unique Formula is as given below initially.

    (if(V1>2.0E-8&&V1<2.0E-7&&V2>2.0E-8&&V2<2.0E-7&&V3>2.0E-8&&V3<2.0E-7&&V4>2.0E-8&&V4<2.0E-7&&V5>2.0E-8&&V5<2.0E-7&&V6>2.0E-8&&V6<2.0E-7&&V7>2.0E-8&&V7<2.0E-7&&V8>2.0E-8&&V8<2.0E-7&&V9>2.0E-8&&V9<2.0E-7&&V10>2.0E-8&&V10<2.0E-7,output=1.0,output=0.0))*1
    The idea behind code is to append a unique number along with v1,v2,v3 and so on to make it unique.
    so after running the piece of code the UniqyeFormula Becomes like this

    (if(V1_0>2.0E-8&&V1_0<2.0E-7&&V2_1>2.0E-8&&V2_1<2.0E-7&&V3_2>2.0E-8&&V3_2<2.0E-7&&V4_3>2.0E-8&&V4_3<2.0E-7&&V5_4>2.0E-8&&V5_4<2.0E-7&&V6_5>2.0E-8&&V6_5<2.0E-7&&V7_6>2.0E-8&&V7_6<2.0E-7&&V8_7>2.0E-8&&V8_7<2.0E-7&&V9_8>2.0E-8&&V9_8<2.0E-7&&V1_00>2.0E-8&&V1_00<2.0E-7,output=1.0,output=0.0))*1
    The issue i face in when Parameter becomes in Double Digit. V1 becomes V1_0 which is correct But V10 Becomes V1_00 which is not correct.


    uniqueFormula = uniqueFormula.replace(keyValue[0],sb.toString());

    This piece of line V1 with V1_0.....but its also searching for V10 and splits it as V1_00.

    Can anyone Suggest how to overcome this issue.

    Regards
    Ashesh


  2. #2
    Junior Member
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Replacing File Content

    Hi,

    Any suggestion using RegEx?

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Replacing File Content

    Any suggestion guys?

  4. #4
    Junior Member
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Replacing File Content

    This made it work perfect.


    uniqueFormula = uniqueFormula.replaceAll("\\b"+keyValue[0]+"\\b",sb.toString());

Similar Threads

  1. [SOLVED] Replacing words in a text file
    By sanelko in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: January 30th, 2012, 01:56 AM
  2. Content in text file to MS Word file help!
    By ComputerSaysNo in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: October 27th, 2011, 11:39 AM
  3. JTextarea content writing into a file
    By ArpanSe in forum AWT / Java Swing
    Replies: 2
    Last Post: September 18th, 2011, 10:12 AM
  4. Want to Update Class File content
    By AlokPatil in forum Member Introductions
    Replies: 1
    Last Post: August 26th, 2011, 11:45 PM
  5. Changing Class File Content
    By xxcorrosionxx in forum Java Networking
    Replies: 2
    Last Post: January 18th, 2011, 07:46 AM