Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Replacing Content of Line using Code

Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Please help to solve this issue.

The above code takes the input as velow

The Formula is just used to test some condition based on result....In above case we use from V1 till V10.The Java code mentioned above is used to conver V1 as V1_0 to uniquely identify each variable by appending a unique number after variable ( like V1 becomes V1_0 and so on ).

The issue i am facing is when i try to convert V1 as V1_0 it is also searching for v10 and converting it as V1_00, similarly for V2 its converting V2 as V2_0 and V20 as V2_00.

This is the result after converting at present.
Please help to modify above code to differentiate between V1 and V10 and so on.


Posts: 76487
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is too difficult for “beginning”, so I shall move it.

You have posted a block of unintelligible text with incomprehensible variable names (V1 V2) and no spaces around operators. Also, the line is too long to read.
I cannot understand the question. What are you trying to do? Are you trying to parse that line? Are you trying to insert “_0” after each number? Are you telling the program to look for V followed by a digit, when it should be V followed by one or more digits?
You might do that by matching a regular expression, possibly for "V\\d+". You might do well to insert backwards. Start with the last occurrence of V\\d+ and work towards the first occurrence. That way the indices you are inserting at will not change. If you find V123 at index 345, you will want to insert at index 349, i.e. index + length of match. That will change any indices after 349, but will not change indices before that.
His brain is the size of a cherry pit! About the size of this ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic