Active IQ Unified Manager Discussions

WFA function to extract portions of a fqdn

skellner
3,021 Views

I try to create a function to extract a portion of a fqdn. When I try it like this I get an error and don't know why. Maybe someone can help me with this.

def extractPrefixArrayName(array_name,region)

{

String hostname = splitByDelimiter(array_name,'\\.',0);

return hostname.Substring(0,1)+hostname.Substring(6,5)+region;

  

}

When I test it with extractPrefixArrayName("g100bpmc002.g100.intern","d") I get the following error

[Error: failed to access property: extractPrefixArrayName("g100bpmc002.g100.intern","d"): [Error: unable to resolve method: java.lang.String.Substring(java.lang.Integer, java.lang.Integer) [arglength=2]]

[Near : {... Unknown ....}]

^

[Line: 1, Column: 0]]

[Near : {... "g100bpmc002.g100.intern","d" ....}]

^

[Line: 1, Column: 0]

1 ACCEPTED SOLUTION

dekel
3,020 Views

Hi,

There are two issues with this function

1) You need to use substring and not Substring   -Java is case sensitive

2) you need to do hostname.substring(5,6) and not hostname.substring(6,5) - Otherwise you will get index of bound

The result of the below function will be

Input :extractPrefixArrayName("g100bpmc002.g100.intern","d")

Output :gpd

def extractPrefixArrayName(array_name,region)

{

String hostname = splitByDelimiter(array_name,'\\.',0);

return hostname.substring(0,1)+hostname.substring(5,6)+region;

  

}

Note that in your function all positions are hard coded (0,1 and 5,6) ,you assume all host names length are the same -not sure if this is indeed true

Hope it helps

View solution in original post

2 REPLIES 2

dekel
3,021 Views

Hi,

There are two issues with this function

1) You need to use substring and not Substring   -Java is case sensitive

2) you need to do hostname.substring(5,6) and not hostname.substring(6,5) - Otherwise you will get index of bound

The result of the below function will be

Input :extractPrefixArrayName("g100bpmc002.g100.intern","d")

Output :gpd

def extractPrefixArrayName(array_name,region)

{

String hostname = splitByDelimiter(array_name,'\\.',0);

return hostname.substring(0,1)+hostname.substring(5,6)+region;

  

}

Note that in your function all positions are hard coded (0,1 and 5,6) ,you assume all host names length are the same -not sure if this is indeed true

Hope it helps

skellner
3,020 Views

Hi,

thanks for your help. My fault was not to recognize that this is Java. So this is good to know.

Best regards

Stefan

Public