<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Manipulate a string in groovy script in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/manipulate-a-string-in-groovy-script/qaa-p/12810621#M4810682</link>
    <description>&lt;P&gt;Hi Jwan,&lt;/P&gt;&lt;P&gt;Thx for your answer. I ran the code in &lt;A rel="nofollow" href="http://www.jdoodle.com/execute-groovy-online" target="_blank"&gt;www.jdoodle.com/execute-groovy-online&lt;/A&gt;/&lt;/P&gt;&lt;P&gt;The output was ".com/mystring/ourstring"&lt;/P&gt;&lt;P&gt;But this is not the desired outcome unfortunately.&lt;/P&gt;&lt;P&gt;The outcome should be "&lt;A rel="nofollow" href="http://URL.something.com/mystring/ourstring" target="_blank"&gt;URL.something.com/mystring/ourstring&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Robert&lt;/P&gt;</description>
    <pubDate>Tue, 17 Oct 2023 08:59:33 GMT</pubDate>
    <dc:creator>Robert_d_Hoedt</dc:creator>
    <dc:date>2023-10-17T08:59:33Z</dc:date>
    <item>
      <title>Manipulate a string in groovy script</title>
      <link>https://community.sap.com/t5/technology-q-a/manipulate-a-string-in-groovy-script/qaq-p/12810619</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
  &lt;P&gt;For my Integration Suite scenario i must manipulate a string.&lt;/P&gt;
  &lt;P&gt;My input is something like: "URL.something.com/string1/string2". &lt;/P&gt;
  &lt;P&gt;The URL.something might change over time (and can be longer or shorter) and the string1/string2 can also change&lt;/P&gt;
  &lt;P&gt;The only part i can be sure of is ".com/"&lt;/P&gt;
  &lt;P&gt;What i need is a Groovy script that will take URL.something.com and replace string1/string2 with something like /mystring/ourstring.&lt;/P&gt;
  &lt;P&gt;Because of the flexible length of URL.something it is not possible to replace after a fixed length. And i can also not replace on the basis of string1/string2 because that can also change.&lt;/P&gt;
  &lt;P&gt;So it needs to be some instruction like: remove everything that comes after ".com/" and then add /mystring/ourstring.&lt;/P&gt;
  &lt;P&gt;Hopefully someone can help me out.&lt;/P&gt;
  &lt;P&gt;Kr&lt;/P&gt;
  &lt;P&gt;Robert&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 14:42:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/manipulate-a-string-in-groovy-script/qaq-p/12810619</guid>
      <dc:creator>Robert_d_Hoedt</dc:creator>
      <dc:date>2023-10-16T14:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulate a string in groovy script</title>
      <link>https://community.sap.com/t5/technology-q-a/manipulate-a-string-in-groovy-script/qaa-p/12810620#M4810681</link>
      <description>&lt;P&gt;Do you mean something like this? &lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;def inputUrl = "URL.something.com/string1/string2"&lt;BR /&gt;def pattern = /(\.com\/)(.+)/

def matcher = (inputUrl =~ pattern)
     if (matcher.find()) {
        def modifiedUrl = matcher.group(1) + "mystring/ourstring"
        println modifiedUrl
     } else {
            println "Pattern not found in the URL"
       }

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Oct 2023 14:55:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/manipulate-a-string-in-groovy-script/qaa-p/12810620#M4810681</guid>
      <dc:creator>Jwan_24</dc:creator>
      <dc:date>2023-10-16T14:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulate a string in groovy script</title>
      <link>https://community.sap.com/t5/technology-q-a/manipulate-a-string-in-groovy-script/qaa-p/12810621#M4810682</link>
      <description>&lt;P&gt;Hi Jwan,&lt;/P&gt;&lt;P&gt;Thx for your answer. I ran the code in &lt;A rel="nofollow" href="http://www.jdoodle.com/execute-groovy-online" target="_blank"&gt;www.jdoodle.com/execute-groovy-online&lt;/A&gt;/&lt;/P&gt;&lt;P&gt;The output was ".com/mystring/ourstring"&lt;/P&gt;&lt;P&gt;But this is not the desired outcome unfortunately.&lt;/P&gt;&lt;P&gt;The outcome should be "&lt;A rel="nofollow" href="http://URL.something.com/mystring/ourstring" target="_blank"&gt;URL.something.com/mystring/ourstring&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Robert&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 08:59:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/manipulate-a-string-in-groovy-script/qaa-p/12810621#M4810682</guid>
      <dc:creator>Robert_d_Hoedt</dc:creator>
      <dc:date>2023-10-17T08:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulate a string in groovy script</title>
      <link>https://community.sap.com/t5/technology-q-a/manipulate-a-string-in-groovy-script/qaa-p/12810622#M4810683</link>
      <description>&lt;P&gt;Hi Jwan,&lt;/P&gt;&lt;P&gt;I think i found something that might work; its called ordinalIndex&lt;/P&gt;&lt;P&gt;serverurl = "https://url.something.com/mystring1/mystring2"&lt;/P&gt;&lt;P&gt;index = ordinalIndexOf(serverurl,'/',3)&lt;/P&gt;&lt;P&gt;println(serverurl.substring(0,index)+""/mystring/ourstring"");&lt;/P&gt;&lt;P&gt;static int ordinalIndexOf(String str, String substr, int n) {&lt;/P&gt;&lt;P&gt;    int pos = str.indexOf(substr);&lt;/P&gt;&lt;P&gt;    while (--n &amp;gt; 0 &amp;amp;&amp;amp; pos != -1)&lt;/P&gt;&lt;P&gt;        pos = str.indexOf(substr, pos + 1);&lt;/P&gt;&lt;P&gt;    return pos;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 10:23:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/manipulate-a-string-in-groovy-script/qaa-p/12810622#M4810683</guid>
      <dc:creator>Robert_d_Hoedt</dc:creator>
      <dc:date>2023-10-17T10:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulate a string in groovy script</title>
      <link>https://community.sap.com/t5/technology-q-a/manipulate-a-string-in-groovy-script/qaa-p/12810623#M4810684</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;So i found something that will work independent of the length of the string&lt;/P&gt;&lt;P&gt;(so it will work for "https://shorturl.com/stringA" and for &lt;A href="https://veryverylongurl.com/string" target="test_blank"&gt;https://veryverylongurl.com/string&lt;/A&gt; A)&lt;/P&gt;&lt;P&gt;First action is to determine what the index of the 3rd "/" is.&lt;/P&gt;&lt;P&gt;Second action is take substring from 0 to index&lt;/P&gt;&lt;P&gt;Third action is to add customstring as a path.&lt;/P&gt;&lt;P&gt;String ServerURL;&lt;/P&gt;&lt;P&gt;static int
ordinalIndexOf(String str, String substr, int n) {&lt;/P&gt;&lt;P&gt;    int pos = str.indexOf(substr);&lt;/P&gt;&lt;P&gt;    while (--n &amp;gt; 0 &amp;amp;&amp;amp; pos != -1)&lt;/P&gt;&lt;P&gt;        pos = str.indexOf(substr, pos + 1);&lt;/P&gt;&lt;P&gt;    return pos;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;index =
ordinalIndexOf(ServerURL,'/',3);&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;ServerURL =
(ServerURL.substring(0,index)+"/addcustomstringasapath");&lt;/P&gt;&lt;P&gt;kr&lt;/P&gt;&lt;P&gt;Robert&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2023 07:34:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/manipulate-a-string-in-groovy-script/qaa-p/12810623#M4810684</guid>
      <dc:creator>Robert_d_Hoedt</dc:creator>
      <dc:date>2023-10-18T07:34:04Z</dc:date>
    </item>
  </channel>
</rss>

