Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

String Function

Is there a string function to convert my string of type servername.na.corp.companyname to servername.

I have to delete the .na.corp.companyname part.

Tags (1)
1 Solution

Accepted Solutions
jerem1234
Valued Contributor II

Re: String Function

What are you expecting to return for a number? the whole number string if its a number?

So maybe try:

=if(isnum(Subfield(YOURFIELD, '.',1)), YOURFIELD, Subfield(YOURFIELD, '.',1))

For 10.32.123.45, this will just return 10.32.123.45. For servername.na.corp.companyname, servername.

Hope this helps!

10 Replies
jerem1234
Valued Contributor II

Re: String Function

=Subfield('servername.na.corp.companyname', '.',1)

Hope this helps!

Not applicable

Re: String Function

Hi,

I think subfield can do that job (but there will be other ways as well).

subfield(s, 'delimiter' [ , index ] )

In its three-parameter version, this script function returns a given substring from a larger string s with delimiter

'delimiter'. index is an optional integer denoting which of the substrings should be returned. If index is

omitted when subfield is used in a field expression in a load statement, the subfield function will cause the

load statement to automatically generate one full record of input data for each substring that can be found in

s.

In its two-parameter version, the subfield function generates one record for each substring that can be taken

from a larger string s with the delimiter 'delimiter'. If several subfield functions are used in the same load

statement, the Cartesian product of all combinations will be generated.

Examples:

subfield(S, ';' ,2) returns 'cde' if S is 'abc;cde;efg'

Regards,

Gerrit

Not applicable

Re: String Function

Thanks a lot for your quick response... It worked really well expect for some servernames are in numeric form and I want them not to change For Example : 10.32.123.45 ... So by using the previous function it is returning me just 10 but that is not intended !!... How do I go around this??

Not applicable

Re: String Function

Thanks a lot for your quick response... It worked really well expect for some servernames are in numeric form and I want them not to change For Example : 10.32.123.45 ... So by using the previous function it is returning me just 10 but that is not intended !!... How do I go around this??

dagomezl
Contributor III

Re: String Function

Subfield('servername.na.corp.companyname', '.',1)

&'.'&

Subfield('servername.na.corp.companyname', '.',2)

&'.'&

Subfield('servername.na.corp.companyname', '.',3)

&'.'&

Subfield('servername.na.corp.companyname', '.',4) as ServerName

jerem1234
Valued Contributor II

Re: String Function

What are you expecting to return for a number? the whole number string if its a number?

So maybe try:

=if(isnum(Subfield(YOURFIELD, '.',1)), YOURFIELD, Subfield(YOURFIELD, '.',1))

For 10.32.123.45, this will just return 10.32.123.45. For servername.na.corp.companyname, servername.

Hope this helps!

Employee
Employee

Re: String Function

na.corp.companyname is always fixed?

If yes

=left('10.32.123.45.na.corp.companyname',index('10.32.123.45.na.corp.companyname','.na.corp.companyname')-1)

jerem1234
Valued Contributor II

Re: String Function

I think I read your post too fast,

If your string looks like 10.32.123.45.na.corp.companyname, then try:

=if(isnum(Subfield(YOURFIELD, '.',1)), left(YOURFIELD, 12), Subfield(YOURFIELD, '.',1))

This assumes the same amount of characters for your numeric representation of your server, if your string is not always 12 characters long, this won't work.

Hope this helps!

Not applicable

Re: String Function

This worked.. thanks...

Community Browser