New Ranks & Badges For The Community!
Notice something different? The ranks and associated badges have gone "Star Fleet". See what they all mean HERE
Highlighted
Absent Member.
Absent Member.
623 views

substring of a variable

Hi,

In a rule I want to take apart DeviceCustomSring1 which has the value "#999.999" into two fields.  So I need to:

(1) Find x = index_of("#999.999", ".")

(2) Find y = SubString( "#999.999", 1, x)

So can I save X above as an intermediate value in this rule and then use x as input to y?----regards, WER

Labels (1)
0 Likes
5 Replies
Highlighted
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

You acutally have it already.  Just store the result of the first funtion into a variable and use that variable in the next function.

getDotIndex = indexOf(deviceCustomString1,".")

getSubString1 = substring(deviceCustomString1,0,getDotIndex)

getAdvIndex = add(getDotIndex,1)

getSubString2 = substring(deviceCustomString1,getAdvIndex,-1)

The getSubString1 will give you the first part, and the getSubString2 will get you the second part.  The getAdvIndex is needed to advance the index one, unless you want the dot.

0 Likes
Highlighted
Absent Member.
Absent Member.

I agree with chris. There is also another way to get the second substring.

1. Use a lengthof variable to grab the total number of characters in the string

2. use a subtract variable to subtract the integer from your first indexof from the integer from lengthof variable

3. substring the string starting your cut at 'subtractvariable' and stopping at 'lengthofvariable'.

this should work best for grabbing the second substring

0 Likes
Highlighted
Absent Member.
Absent Member.

If you need to copy until the end of a string, there's no need to get the length of that string. Just use -1 

0 Likes
Absent Member.
Absent Member.

I had to solve the same issue today...

I have a string, seperated by pipe symbol.

I created two helper variables, containing the position of the seperators:

deviceCustomSting="1111|2222|3333"

sep_01=indexOf(deviceCustomString3;|)

sep_02=lastIndexOf(deviceCustomString3;|)

substring_01=

substring_02=

substring_03=

But if you use those both to get the substrings into your variables, your delimiter will be part of it as the substring bondaries include the postions of the seperator.

So you have to

- subtract the sep_01 by one to get the "1111" into substring_01 instead of "1111|"

Therefore i created another helper variable, called sep_01-minus by using sep_01-minus=subtract(sep_01;1)

Now i can get the substring_01 variable filled by

substring_01=substring(deviceCustomString3;0;sep_01-minus)

this goes the same way for substring_02 which is substring(deviceCustomString;sep_01-plus;sep02-minus)

and for substring_03 as substring(deviceCustomString;sep_02-plus;-1)

Feels not like the silver bullet or very intuitive but IMHO this is the only way as you cannot combine functions within a single variable definition.

Furthermore you probably don't want the seperator character being a part of your custom variable.

HTH,

Markus

0 Likes
Highlighted
Absent Member.
Absent Member.

Markus,

I might have misunderstood, but if you want '1111' for substring_01, you need to use sep_01, not sep_01-minus. The substring function does NOT include the character at the position specified by the second parameter.

By the way, there's another way to manipulate strings: velocity template. It's way more powerful and convenient. The catch, however, is you can't use variables with velocity code for reports.

There was one time when I had to write 60 variables to process a string. The samething took 2 lines of velocity code.

_Duc

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.