on 2023 Oct 16 3:42 PM
Hi,
For my Integration Suite scenario i must manipulate a string.
My input is something like: "URL.something.com/string1/string2".
The URL.something might change over time (and can be longer or shorter) and the string1/string2 can also change
The only part i can be sure of is ".com/"
What i need is a Groovy script that will take URL.something.com and replace string1/string2 with something like /mystring/ourstring.
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.
So it needs to be some instruction like: remove everything that comes after ".com/" and then add /mystring/ourstring.
Hopefully someone can help me out.
Kr
Robert
Hi all,
So i found something that will work independent of the length of the string
(so it will work for "https://shorturl.com/stringA" and for https://veryverylongurl.com/string A)
First action is to determine what the index of the 3rd "/" is.
Second action is take substring from 0 to index
Third action is to add customstring as a path.
String ServerURL;
static int ordinalIndexOf(String str, String substr, int n) {
int pos = str.indexOf(substr);
while (--n > 0 && pos != -1)
pos = str.indexOf(substr, pos + 1);
return pos;
}
index = ordinalIndexOf(ServerURL,'/',3);
ServerURL = (ServerURL.substring(0,index)+"/addcustomstringasapath");
kr
Robert
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
10 | |
10 | |
10 | |
10 | |
9 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.