How do I get a string value prior to a specific character in the the string in a server script?

gjz
Mega Sage

In our company, the host name of our CIs are in the format of friendlyname.domain, and the domain also has several periods in it.  For example, one of the CI's hostname could be

    wc123456.some.domain.name

 

I need to get the data in the host name up to the 1st period in the host name - in the above example, wc123456.  The length of the friendlyname portion of the host name is variable in length.

 

What is the correct Javascript syntax that will accomplish this?

1 REPLY 1

SAI VENKATESH
Tera Sage
Tera Sage

Hi @gjz 

 

You can extract the hostname either by using split or index of 

 

Code :

 

var hostname = "wc123456.some.domain.name"; 
var friendlyName = hostname.split('.')[0]; // spliting until the first .(dot)

gs.print(friendlyName);  // Output: wc123456

 

Thanks and Regards

Sai Venkatesh