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 2 of 2

Thread: How can multiple substrings of a String be replaced with multiple values in java?

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool How can multiple substrings of a String be replaced with multiple values in java?

    I have a long String which is dynamic. Wherever % XXX % is found, I have to get the XXX value and replace it with some other value. There will be multiple % XXX %. How can I get the value within the % %?

    For Eg.

    "POLICY_NO = %POLNO% and b.ACTION_TIME = (select max(ACTION_TIME) from POLICY_DETAILS where POLICY_NO = %POLICYID%)"

    How can I read each value between 2 %? And I have to take POLNO and compare it with some session variables(Eg,POLNO=1234567,POLICYID=3) and if it is matched then i have to replace the session variable value. Then the query sholud become as

    "POLICY_NO = 1234567 and b.ACTION_TIME = (select max(ACTION_TIME) from POLICY_DETAILS where POLICY_NO = 3)"


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,332
    Thanks
    181
    Thanked 829 Times in 772 Posts
    Blog Entries
    5

    Default Re: How can multiple substrings of a String be replaced with multiple values in java?

    See Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes)
    And note that the string.replaceAll method uses regular expressions
    Last edited by copeg; April 26th, 2012 at 10:08 AM.

Similar Threads

  1. retrieve data from database using Hashmap (multiple values in one key)
    By ashin12 in forum Collections and Generics
    Replies: 2
    Last Post: April 4th, 2012, 05:22 AM
  2. Replies: 6
    Last Post: December 9th, 2011, 04:53 PM
  3. Finding Multiple Equal Max Values in an Array
    By AbsolutelyNobody in forum Collections and Generics
    Replies: 4
    Last Post: October 30th, 2011, 03:07 AM
  4. [SOLVED] Define a String as multiple things
    By bgroenks96 in forum Java Theory & Questions
    Replies: 10
    Last Post: June 7th, 2011, 09:57 AM
  5. adding multiple ints into a string
    By straw in forum Java Theory & Questions
    Replies: 1
    Last Post: March 18th, 2010, 06:02 PM

Tags for this Thread