Forum Discussion

SankarB's avatar
SankarB
Occasional Contributor
7 years ago

Replace and insert

How can i search for a string and replace with the another value.

 

I have requirement of some like this 

 

"-------------- Start String -------

                                             Actual string

 

-----End String --------"

 

Basically i need to pass only "Actual string" and need to ignore the rest of "------ Start String " "----- Stop String-----"

 

Can any one pls help me in this.

 

 i have tried with 

def a = 

                     "-------------- Start String -------

                                             Actual string

 

                        -----End String --------"

a.replace("Start String", "").

But its not actually not working.

 

Can any one pls help me in this. 

 

Thanks in advance.

 

 

 

 

2 Replies

    • groovyguy's avatar
      groovyguy
      Champion Level 1

      Try something like the snippet below. If you use ''' (three single quotes) instead of " (one double quote) to denote a string, it'll take any/all special formatting of the string. Then, when you use replace, you have to set something equal to the result of the .replace() function.

       

      def a = '''-------------- Start String -------
      
                                                   Actual string
      
       
      
                              -----End String --------'''
      
      a = a.replace("Start String", "");
      
      log.info(a);